Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/05/18 15:13:25 (7 years ago)
Author:
jzenisek
Message:

#2839 worked on service side mgmt of project-resource assignments and project-user permissions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs

    r15552 r15577  
    7575    // authorize if user is admin or resource owner
    7676    public void AuthorizeForResourceAdministration(Guid resourceId) {
     77      var currentUserId = UserManager.CurrentUserId;
    7778      var pm = PersistenceManager;
    7879      var resourceDao = pm.ResourceDao;
     
    8182        if (resource == null) throw new SecurityException(NOT_AUTHORIZED_USERRESOURCE);
    8283
    83         if (resource.OwnerUserId != UserManager.CurrentUserId
     84        if (resource.OwnerUserId != currentUserId
    8485            && !RoleVerifier.IsInRole(HiveRoles.Administrator)) {
    8586          throw new SecurityException(NOT_AUTHORIZED_USERRESOURCE);
     
    9091    // authorize if user is admin, project owner or owner of a parent project
    9192    public void AuthorizeForProjectAdministration(Guid projectId) {
     93      if (projectId == null) return;
     94      var currentUserId = UserManager.CurrentUserId;
    9295      var pm = PersistenceManager;
    9396      var projectDao = pm.ProjectDao;
     
    98101
    99102        var projectBranch = projectDao.GetCurrentAndParentProjectsById(projectId);
    100         if(!projectBranch.Select(x => x.OwnerUserId).Contains(UserManager.CurrentUserId)
     103        if(!projectBranch.Select(x => x.OwnerUserId).Contains(currentUserId)
    101104            && !RoleVerifier.IsInRole(HiveRoles.Administrator)) {
    102105          throw new SecurityException(NOT_AUTHORIZED_USERPROJECT);
     
    107110    // authorize if user is admin, or owner of a parent project, for which the resources are assigned to
    108111    public void AuthorizeForProjectResourceAdministration(Guid projectId, IEnumerable<Guid> resourceIds) {
     112      if (projectId == null) return;
     113      var currentUserId = UserManager.CurrentUserId;
    109114      var pm = PersistenceManager;
    110115      var projectDao = pm.ProjectDao;
     
    117122
    118123        // check if resourceIds exist
    119         if (!resourceDao.CheckExistence(resourceIds))
     124        if (resourceIds != null && resourceIds.Any() && !resourceDao.CheckExistence(resourceIds))
    120125          throw new SecurityException(NOT_AUTHORIZED_USERRESOURCE);
    121126
     
    123128        if (RoleVerifier.IsInRole(HiveRoles.Administrator)) return;
    124129
    125         // check if user is owner of a parent project and...
     130        // check if user is owner of a parent project
     131        var projectBranch = projectDao.GetParentProjectsById(projectId);
     132        if (!projectBranch.Select(x => x.OwnerUserId).Contains(currentUserId)
     133            && !RoleVerifier.IsInRole(HiveRoles.Administrator)) {
     134          throw new SecurityException(NOT_AUTHORIZED_USERPROJECT);
     135        }
     136
    126137        // check if the all argument resourceIds are among the assigned resources of the owned projects
    127         var grantedResourceIds = assignedProjectResourceDao.GetAllGrantedResourceIdsOfOwnedParentProjects(projectId, UserManager.CurrentUserId);
     138        var grantedResourceIds = assignedProjectResourceDao.GetAllGrantedResourceIdsOfOwnedParentProjects(projectId, currentUserId);
    128139        if(resourceIds.Except(grantedResourceIds).Any()) {
    129140          throw new SecurityException(NOT_AUTHORIZED_USERRESOURCE);
     
    134145    // Check if a project is authorized to use a list of resources
    135146    public void AuthorizeProjectForResourcesUse(Guid projectId, IEnumerable<Guid> resourceIds) {
     147      if (projectId == null || resourceIds == null || !resourceIds.Any()) return;
    136148      var pm = PersistenceManager;
    137149      var assignedProjectResourceDao = pm.AssignedProjectResourceDao;
     
    143155    // note: administrators and project owner are NOT automatically granted
    144156    public void AuthorizeUserForProjectUse(Guid userId, Guid projectId) {
     157      if (userId == null || projectId == null) return;
    145158      var pm = PersistenceManager;
    146159      // collect current and group membership Ids
     
    166179
    167180    private void AuthorizeJob(IPersistenceManager pm, Guid jobId, DT.Permission requiredPermission) {
     181      var currentUserId = UserManager.CurrentUserId;
    168182      var requiredPermissionEntity = requiredPermission.ToEntity();
    169       DA.Permission permission = GetPermissionForJob(pm, jobId, UserManager.CurrentUserId);
     183      DA.Permission permission = GetPermissionForJob(pm, jobId, currentUserId);
    170184      if (permission == Permission.NotAllowed
    171185          || ((permission != requiredPermissionEntity) && requiredPermissionEntity == Permission.Full)) {
Note: See TracChangeset for help on using the changeset viewer.