@@ -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 *
0 commit comments