Skip to content

Commit

Permalink
Merge pull request #172 from rwth-acis/feature/user-authorization-inf…
Browse files Browse the repository at this point in the history
…ormation

Feature/user authorization information
  • Loading branch information
fxjordan authored Jul 8, 2022
2 parents 246b4ef + 3e59b4d commit 9aae2ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public class UserContext extends EntityBase {
)
private Boolean isContributor;

@ApiModelProperty(
value = "Whether the user has privilege to move the requirement. Only returned when requesting requirement resources."
)
private Boolean isMoveAllowed;

@ApiModelProperty(
value = "Whether the user has privilege to delete the requirement, category, or project."
)
private Boolean isDeleteAllowed;

@JsonIgnore
@Override
public int getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import de.rwth.dbis.acis.bazaar.service.exception.ErrorCode;
import de.rwth.dbis.acis.bazaar.service.exception.ExceptionHandler;
import de.rwth.dbis.acis.bazaar.service.exception.ExceptionLocation;
import de.rwth.dbis.acis.bazaar.service.security.AuthorizationManager;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.jetbrains.annotations.NotNull;
import org.jooq.Record;
Expand Down Expand Up @@ -311,6 +312,12 @@ private ImmutablePair<List<Requirement>, Integer> getFilteredRequirements(Collec
requirement.setAttachments(attachmentList);
}

// TODO We should refactor here: the same authorization check is made in the RequirementResource#moveRequirement(..) method
boolean authorizedToModifyRequirement = new AuthorizationManager().isAuthorizedInContext(userId, PrivilegeEnum.Modify_REQUIREMENT, requirement.getProjectId(), dalFacade);
userContext.isMoveAllowed(authorizedToModifyRequirement);

userContext.isDeleteAllowed(authorizedToModifyRequirement || requirement.isOwner(userId));

requirement.setContext(EntityContextFactory.create(pageable.getEmbed(), queryResult, dalFacade));
requirement.setUserContext(userContext.build());
requirements.add(requirement);
Expand Down

0 comments on commit 9aae2ea

Please sign in to comment.