Skip to content

Commit

Permalink
Merge pull request #181 from rwth-acis/feature/tags
Browse files Browse the repository at this point in the history
Make tags customizable
  • Loading branch information
Tobasco99 authored May 30, 2023
2 parents f6901bc + 20a6042 commit a9fbf7c
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,20 @@ public interface DALFacade {
* @throws Exception
*/
void untagRequirement(int tagId, int requirementId) throws Exception;

/**
* Updates a Tag
*
* @param tag comment to persist
* @return the updated comment
* @throws Exception
*/
Tag updateTag(Tag tag) throws Exception;

/**
* @param tagId to identify the comment to be deleted
*/
Tag deleteTagById(int tagId) throws Exception;
// endregion tags


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,21 @@ public void untagRequirement(int tagId, int requirementId) throws Exception {
requirementTagRepository.delete(tagId, requirementId);
}

@Override
public Tag updateTag(Tag tag) throws Exception {
tagRepository = (tagRepository != null) ? tagRepository : new TagRepositoryImpl(dslContext);
tagRepository.update(tag);
return tagRepository.findById(tag.getId());
}

@Override
public Tag deleteTagById(int tagId) throws Exception {
tagRepository = (tagRepository != null) ? tagRepository : new TagRepositoryImpl(dslContext);
Tag tag = tagRepository.findById(tagId);
tagRepository.delete(tagId);
return tag;
}

@Override
public PaginationResult<ProjectMember> getProjectMembers(int projectId, Pageable pageable) throws
BazaarException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ public Response getTagsForProject(
}

/**
* This method add the current user to the followers list of a given project.
* This method adds a tag to a given project.
*
* @param projectId id of the project
* @param tag Tag to be created
Expand All @@ -693,7 +693,8 @@ public Response createTag(@PathParam("projectId") int projectId,
dalFacade = bazaarService.getDBConnection();
Integer internalUserId = dalFacade.getUserIdByLAS2PeerId(userId);

resourceHelper.checkAuthorization(new AuthorizationManager().isAuthorized(internalUserId, PrivilegeEnum.Create_CATEGORY, dalFacade), "error.authorization.category.create", true);
// Only Admins should be able to create new tags.
resourceHelper.checkAuthorization(new AuthorizationManager().isAuthorizedInContext(internalUserId, PrivilegeEnum.Modify_PROJECT, projectId, dalFacade), "error.authorization.project.modify", true);

// Ensure no cross-injection happens
tag.setProjectId(projectId);
Expand All @@ -711,6 +712,84 @@ public Response createTag(@PathParam("projectId") int projectId,
}
}

/**
* Allows to update a tag of a project.
*
* @param projectId id of the project to update
* @param tag One modified project tag
* @return Response with empty body.
*/
@PUT
@Path("/{projectId}/tags")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "This method allows to modify a project tag.")
@ApiResponses(value = {
@ApiResponse(code = HttpURLConnection.HTTP_NO_CONTENT, message = "Member modified"),
@ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized"),
@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found"),
@ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal server problems")
})
public Response updateTags(@PathParam("projectId") int projectId,
@ApiParam(value = "New or updated tags", required = true) Tag tag) {
DALFacade dalFacade = null;
try {
String userId = resourceHelper.getUserId();
resourceHelper.handleGenericError(bazaarService.validate(tag));

dalFacade = bazaarService.getDBConnection();
Integer internalUserId = dalFacade.getUserIdByLAS2PeerId(userId);
// Only Admins should be able to edit tags.
resourceHelper.checkAuthorization(new AuthorizationManager().isAuthorizedInContext(internalUserId, PrivilegeEnum.Modify_PROJECT, projectId, dalFacade), "error.authorization.project.modify", true);


// ensure the given tag exists
dalFacade.getTagById(tag.getId());
dalFacade.updateTag(tag);
bazaarService.getNotificationDispatcher().dispatchNotification(OffsetDateTime.now(), Activity.ActivityAction.UPDATE, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_6, projectId, Activity.DataType.PROJECT, internalUserId);
return Response.noContent().build();
} catch (BazaarException bex) {
return resourceHelper.handleBazaarException(bex, "Update tag", logger);
} catch (Exception ex) {
return resourceHelper.handleException(ex, "Update tag", logger);
} finally {
bazaarService.closeDBConnection(dalFacade);
}
}

@DELETE
@Path("/{projectId}/tags/{tagId}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "This method allows to remove a tag.")
@ApiResponses(value = {
@ApiResponse(code = HttpURLConnection.HTTP_NO_CONTENT, message = "Tag removed"),
@ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized"),
@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found"),
@ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal server problems")
})
public Response removeTag(
@ApiParam(value = "Project to remove the tag from") @PathParam("projectId") int projectId,
@ApiParam(value = "Tag ID of the Tag to remove") @PathParam("tagId") int tagId) {
DALFacade dalFacade = null;
try {
String userId = resourceHelper.getUserId();
dalFacade = bazaarService.getDBConnection();
Integer internalUserId = dalFacade.getUserIdByLAS2PeerId(userId);
// Only Admins should be able to delete tags.
resourceHelper.checkAuthorization(new AuthorizationManager().isAuthorizedInContext(internalUserId, PrivilegeEnum.Modify_PROJECT, projectId, dalFacade), "error.authorization.project.modify", true);

dalFacade.deleteTagById(tagId);
bazaarService.getNotificationDispatcher().dispatchNotification(OffsetDateTime.now(), Activity.ActivityAction.UPDATE, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_6, projectId, Activity.DataType.PROJECT, internalUserId);
return Response.noContent().build();
} catch (BazaarException bex) {
return resourceHelper.handleBazaarException(bex, "Remove tag", logger);
} catch (Exception ex) {
return resourceHelper.handleException(ex, "Remove tag", logger);
} finally {
bazaarService.closeDBConnection(dalFacade);
}
}

/**
* Add a member to the project
*
Expand Down
1 change: 1 addition & 0 deletions reqbaz/src/main/resources/i18n/Translation_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ error.registrars=Unknown error in registrators.
error.first_login=Error during registering users at first login.
error.authorization.project.create=Only logged-in users can create projects.
error.authorization.anonymous=Even anonymous should be able to watch this. Inform maintainers.
error.authorization.tag.create=Only admins can create tags.
error.authorization.category.read=Only project members can see categories.
error.authorization.category.create=Only admins can create categories.
error.authorization.category.modify=Only admins can modify categories.
Expand Down

0 comments on commit a9fbf7c

Please sign in to comment.