Skip to content

Commit b53bf55

Browse files
authored
Merge pull request #182 from rwth-acis/develop
v0.17.1
2 parents 93ec0ea + 64c731f commit b53bf55

File tree

5 files changed

+118
-2
lines changed

5 files changed

+118
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ the [GitHub Release Page](https://github.com/rwth-acis/RequirementsBazaar/releas
1010

1111
## [Unreleased]
1212

13+
## [0.17.1] - 2023-06-13
14+
15+
### Added
16+
17+
- Added possibility to edit / delete labels
18+
[#181](https://github.com/rwth-acis/RequirementsBazaar/pull/181)
19+
1320
## [0.17.0] - 2023-05-10
1421

1522
### Added

reqbaz/src/main/java/de/rwth/dbis/acis/bazaar/service/dal/DALFacade.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,20 @@ public interface DALFacade {
830830
* @throws Exception
831831
*/
832832
void untagRequirement(int tagId, int requirementId) throws Exception;
833+
834+
/**
835+
* Updates a Tag
836+
*
837+
* @param tag comment to persist
838+
* @return the updated comment
839+
* @throws Exception
840+
*/
841+
Tag updateTag(Tag tag) throws Exception;
842+
843+
/**
844+
* @param tagId to identify the comment to be deleted
845+
*/
846+
Tag deleteTagById(int tagId) throws Exception;
833847
// endregion tags
834848

835849

reqbaz/src/main/java/de/rwth/dbis/acis/bazaar/service/dal/DALFacadeImpl.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,21 @@ public void untagRequirement(int tagId, int requirementId) throws Exception {
974974
requirementTagRepository.delete(tagId, requirementId);
975975
}
976976

977+
@Override
978+
public Tag updateTag(Tag tag) throws Exception {
979+
tagRepository = (tagRepository != null) ? tagRepository : new TagRepositoryImpl(dslContext);
980+
tagRepository.update(tag);
981+
return tagRepository.findById(tag.getId());
982+
}
983+
984+
@Override
985+
public Tag deleteTagById(int tagId) throws Exception {
986+
tagRepository = (tagRepository != null) ? tagRepository : new TagRepositoryImpl(dslContext);
987+
Tag tag = tagRepository.findById(tagId);
988+
tagRepository.delete(tagId);
989+
return tag;
990+
}
991+
977992
@Override
978993
public PaginationResult<ProjectMember> getProjectMembers(int projectId, Pageable pageable) throws
979994
BazaarException {

reqbaz/src/main/java/de/rwth/dbis/acis/bazaar/service/resources/ProjectsResource.java

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ public Response getTagsForProject(
668668
}
669669

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

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

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

715+
/**
716+
* Allows to update a tag of a project.
717+
*
718+
* @param projectId id of the project to update
719+
* @param tag One modified project tag
720+
* @return Response with empty body.
721+
*/
722+
@PUT
723+
@Path("/{projectId}/tags")
724+
@Consumes(MediaType.APPLICATION_JSON)
725+
@Produces(MediaType.APPLICATION_JSON)
726+
@ApiOperation(value = "This method allows to modify a project tag.")
727+
@ApiResponses(value = {
728+
@ApiResponse(code = HttpURLConnection.HTTP_NO_CONTENT, message = "Member modified"),
729+
@ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized"),
730+
@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found"),
731+
@ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal server problems")
732+
})
733+
public Response updateTags(@PathParam("projectId") int projectId,
734+
@ApiParam(value = "New or updated tags", required = true) Tag tag) {
735+
DALFacade dalFacade = null;
736+
try {
737+
String userId = resourceHelper.getUserId();
738+
resourceHelper.handleGenericError(bazaarService.validate(tag));
739+
740+
dalFacade = bazaarService.getDBConnection();
741+
Integer internalUserId = dalFacade.getUserIdByLAS2PeerId(userId);
742+
// Only Admins should be able to edit tags.
743+
resourceHelper.checkAuthorization(new AuthorizationManager().isAuthorizedInContext(internalUserId, PrivilegeEnum.Modify_PROJECT, projectId, dalFacade), "error.authorization.project.modify", true);
744+
745+
746+
// ensure the given tag exists
747+
dalFacade.getTagById(tag.getId());
748+
dalFacade.updateTag(tag);
749+
bazaarService.getNotificationDispatcher().dispatchNotification(OffsetDateTime.now(), Activity.ActivityAction.UPDATE, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_6, projectId, Activity.DataType.PROJECT, internalUserId);
750+
return Response.noContent().build();
751+
} catch (BazaarException bex) {
752+
return resourceHelper.handleBazaarException(bex, "Update tag", logger);
753+
} catch (Exception ex) {
754+
return resourceHelper.handleException(ex, "Update tag", logger);
755+
} finally {
756+
bazaarService.closeDBConnection(dalFacade);
757+
}
758+
}
759+
760+
@DELETE
761+
@Path("/{projectId}/tags/{tagId}")
762+
@Produces(MediaType.APPLICATION_JSON)
763+
@ApiOperation(value = "This method allows to remove a tag.")
764+
@ApiResponses(value = {
765+
@ApiResponse(code = HttpURLConnection.HTTP_NO_CONTENT, message = "Tag removed"),
766+
@ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized"),
767+
@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found"),
768+
@ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal server problems")
769+
})
770+
public Response removeTag(
771+
@ApiParam(value = "Project to remove the tag from") @PathParam("projectId") int projectId,
772+
@ApiParam(value = "Tag ID of the Tag to remove") @PathParam("tagId") int tagId) {
773+
DALFacade dalFacade = null;
774+
try {
775+
String userId = resourceHelper.getUserId();
776+
dalFacade = bazaarService.getDBConnection();
777+
Integer internalUserId = dalFacade.getUserIdByLAS2PeerId(userId);
778+
// Only Admins should be able to delete tags.
779+
resourceHelper.checkAuthorization(new AuthorizationManager().isAuthorizedInContext(internalUserId, PrivilegeEnum.Modify_PROJECT, projectId, dalFacade), "error.authorization.project.modify", true);
780+
781+
dalFacade.deleteTagById(tagId);
782+
bazaarService.getNotificationDispatcher().dispatchNotification(OffsetDateTime.now(), Activity.ActivityAction.UPDATE, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_6, projectId, Activity.DataType.PROJECT, internalUserId);
783+
return Response.noContent().build();
784+
} catch (BazaarException bex) {
785+
return resourceHelper.handleBazaarException(bex, "Remove tag", logger);
786+
} catch (Exception ex) {
787+
return resourceHelper.handleException(ex, "Remove tag", logger);
788+
} finally {
789+
bazaarService.closeDBConnection(dalFacade);
790+
}
791+
}
792+
714793
/**
715794
* Add a member to the project
716795
*

reqbaz/src/main/resources/i18n/Translation_en.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ error.registrars=Unknown error in registrators.
2323
error.first_login=Error during registering users at first login.
2424
error.authorization.project.create=Only logged-in users can create projects.
2525
error.authorization.anonymous=Even anonymous should be able to watch this. Inform maintainers.
26+
error.authorization.tag.create=Only admins can create tags.
2627
error.authorization.category.read=Only project members can see categories.
2728
error.authorization.category.create=Only admins can create categories.
2829
error.authorization.category.modify=Only admins can modify categories.

0 commit comments

Comments
 (0)