Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15658


Ignore:
Timestamp:
01/26/18 08:51:30 (6 years ago)
Author:
jzenisek
Message:

#2839

  • worked on (restricted) accessibility of hive's administration area for non-admin roles
  • adapted HiveClient & HiveAdminClient entity loading (client- & service-side)
Location:
branches/HiveProjectManagement
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/MenuItems/AdministratorMenuItem.cs

    r15401 r15658  
    3838
    3939    public override void Execute() {
    40       if (HiveRoles.CheckAdminUserPermissions()) {
     40
     41      if (HiveRoles.CheckAdminUserPermissions() || HiveAdminClient.Instance.CheckAccessToAdminAreaGranted()) {
    4142        MainFormManager.MainForm.ShowContent(HiveAdminClient.Instance);
    4243      } else if (!UserInformation.Instance.UserExists) {
  • branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectResourcesView.cs

    r15642 r15658  
    4444    private readonly HashSet<Resource> inheritedResources = new HashSet<Resource>();
    4545    private readonly HashSet<Resource> newInheritedResources = new HashSet<Resource>();
     46
     47    private readonly Dictionary<Guid, HashSet<Project>> projectAncestors = new Dictionary<Guid, HashSet<Project>>();
     48    private readonly Dictionary<Guid, HashSet<Project>> projectDescendants = new Dictionary<Guid, HashSet<Project>>();
    4649    private readonly Dictionary<Guid, HashSet<Resource>> resourceAncestors = new Dictionary<Guid, HashSet<Resource>>();
    4750    private readonly Dictionary<Guid, HashSet<Resource>> resourceDescendants = new Dictionary<Guid, HashSet<Resource>>();
     51
    4852    //private readonly Color addedAssignmentColor = Color.FromArgb(255, 0, 174, 179); // #00aeb3
    4953    private readonly Color addedAssignmentColor = Color.FromArgb(255, 87, 191, 193); // #57bfc1
     
    7579        detailsViewHost.Content = null;
    7680      } else {
     81        UpdateProjectGenealogy();
    7782        UpdateAssignedResources();
    7883        UpdateResourceGenealogy();
     
    9196
    9297    private void refreshButton_Click(object sender, EventArgs e) {
     98      UpdateProjectGenealogy();
    9399      UpdateAssignedResources();
    94100      UpdateResourceGenealogy();
     
    120126    private void treeView_BeforeCheck(object sender, TreeViewCancelEventArgs e) {
    121127      var checkedResource = (Resource)e.Node.Tag;
    122       if (newInheritedResources.Contains(checkedResource) || checkedResource.Id == Guid.Empty) e.Cancel = true;
     128      if (newInheritedResources.Contains(checkedResource) || checkedResource.Id == Guid.Empty) {
     129        e.Cancel = true;
     130      } else if (!HiveRoles.CheckAdminUserPermissions()) {
     131          if (!projectAncestors[Content.Id].Any()) {
     132            e.Cancel = true;
     133          }
     134      }
    123135    }
    124136
     
    285297        if (newAssignedResources.Contains(newResource)) {
    286298          newNode.Checked = true;
     299          if(!HiveRoles.CheckAdminUserPermissions()) {
     300            if(!projectAncestors[Content.Id].Any()) {
     301              newNode.ForeColor = SystemColors.GrayText;
     302              newNode.Text += " [immutable]";
     303            }
     304          }
     305
    287306        } else if (newInheritedResources.Contains(newResource)) {
    288307          newNode.Checked = true;
     
    331350      }
    332351
    333       var ungroupedNode = new TreeNode(ungroupedGroupName) {
    334         ForeColor = SystemColors.GrayText,
    335         Tag = new SlaveGroup() {
    336           Name = ungroupedGroupName,
    337           Description = ungroupedGroupDescription
    338         }
    339       };
    340 
    341       foreach (var slave in subResources.OfType<Slave>().OrderBy(x => x.Name)) {
    342         var slaveNode = new TreeNode(slave.Name) { Tag = slave };
    343         ungroupedNode.Nodes.Add(slaveNode);
    344       }
    345 
    346       treeView.Nodes.Add(ungroupedNode);
     352      var ungroupedSlaves = subResources.OfType<Slave>().OrderBy(x => x.Name);
     353      if(ungroupedSlaves.Any()) {
     354        var ungroupedNode = new TreeNode(ungroupedGroupName) {
     355          ForeColor = SystemColors.GrayText,
     356          Tag = new SlaveGroup() {
     357            Name = ungroupedGroupName,
     358            Description = ungroupedGroupDescription
     359          }
     360        };
     361
     362        foreach (var slave in ungroupedSlaves) {
     363          var slaveNode = new TreeNode(slave.Name) { Tag = slave };
     364          ungroupedNode.Nodes.Add(slaveNode);
     365        }
     366        treeView.Nodes.Add(ungroupedNode);
     367      }
     368
    347369      treeView.BeforeCheck += treeView_BeforeCheck;
    348370      treeView.AfterCheck += treeView_AfterCheck;
     
    352374    }
    353375
     376    private void UpdateProjectGenealogy() {
     377      projectAncestors.Clear();
     378      projectDescendants.Clear();
     379      var projects = HiveAdminClient.Instance.Projects;
     380
     381      foreach(var p in projects) {
     382        projectAncestors.Add(p.Id, new HashSet<Project>());
     383        projectDescendants.Add(p.Id, new HashSet<Project>());
     384      }
     385
     386      foreach (var p in projects) {
     387        var parentProjectId = p.ParentProjectId;
     388        while (parentProjectId != null) {
     389          var parent = projects.SingleOrDefault(x => x.Id == parentProjectId);
     390          if (parent != null) {
     391            projectAncestors[p.Id].Add(parent);
     392            projectDescendants[parent.Id].Add(p);
     393            parentProjectId = parent.ParentProjectId;
     394          } else {
     395            parentProjectId = null;
     396          }
     397        }
     398      }
     399    }
     400
    354401    #endregion
    355402  }
  • branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectsView.cs

    r15627 r15658  
    270270      //  selectedProject.PropertyChanged += ProjectViewContent_PropertyChanged;
    271271
    272       if (IsAuthorized(selectedProject)) {
    273         if (!tabControl.TabPages.Contains(permissionsTabPage))
    274           tabControl.TabPages.Add(permissionsTabPage);
    275         if (!tabControl.TabPages.Contains(resourcesTabPage))
    276           tabControl.TabPages.Add(resourcesTabPage);
    277       } else {
    278         if (tabControl.TabPages.Contains(permissionsTabPage))
    279           tabControl.TabPages.Remove(permissionsTabPage);
    280         if (tabControl.TabPages.Contains(resourcesTabPage))
    281           tabControl.TabPages.Remove(resourcesTabPage);
    282       }
     272      //if (IsAuthorized(selectedProject)) {
     273      //  if (!tabControl.TabPages.Contains(permissionsTabPage))
     274      //    tabControl.TabPages.Add(permissionsTabPage);
     275      //  if (!tabControl.TabPages.Contains(resourcesTabPage))
     276      //    tabControl.TabPages.Add(resourcesTabPage);
     277      //} else {
     278      //  if (tabControl.TabPages.Contains(permissionsTabPage))
     279      //    tabControl.TabPages.Remove(permissionsTabPage);
     280      //  if (tabControl.TabPages.Contains(resourcesTabPage))
     281      //    tabControl.TabPages.Remove(resourcesTabPage);
     282      //}
    283283    }
    284284
     
    416416
    417417    private bool IsAuthorized(Project project) {
    418       return project != null
    419           && UserInformation.Instance.UserExists
    420           && (project.OwnerUserId == UserInformation.Instance.User.Id || HiveRoles.CheckAdminUserPermissions());
     418      return project != null && UserInformation.Instance.UserExists;
     419          //&& (project.OwnerUserId == UserInformation.Instance.User.Id || HiveRoles.CheckAdminUserPermissions());
    421420    }
    422421
  • branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs

    r15576 r15658  
    302302
    303303      var mainResources = new HashSet<Resource>(resources.OfType<SlaveGroup>().Where(x => x.ParentResourceId == null));
    304       var subResources = new HashSet<Resource>(resources.Except(mainResources));
     304      var parentedMainResources = new HashSet<Resource>(resources.OfType<SlaveGroup>()
     305        .Where(x => x.ParentResourceId.HasValue && !resources.Select(y => y.Id).Contains(x.ParentResourceId.Value)));
     306      mainResources.UnionWith(parentedMainResources);
     307      var subResources = new HashSet<Resource>(resources.Except(mainResources).OrderByDescending(x => x.Name));
    305308
    306309      var stack = new Stack<Resource>(mainResources.OrderByDescending(x => x.Name));
    307       var top = stack.Peek();
     310      Resource top = null;
    308311
    309312      TreeNode currentNode = null;
     
    311314
    312315      while(stack.Any()) {
     316        if (top == null) top = stack.Peek();
    313317        var newResource = stack.Pop();
    314318        var newNode = new TreeNode(newResource.Name) { Tag = newResource };
  • branches/HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelector.cs

    r15642 r15658  
    468468    private static IEnumerable<Resource> GetAssignedResourcesForProject(Guid projectId) {
    469469      var assignedProjectResources = HiveServiceLocator.Instance.CallHiveService(s => s.GetAssignedResourcesForProject(projectId));
    470       return HiveAdminClient.Instance.Resources.Where(x => assignedProjectResources.Select(y => y.ResourceId).Contains(x.Id));
     470      return HiveClient.Instance.Resources.Where(x => assignedProjectResources.Select(y => y.ResourceId).Contains(x.Id));
    471471    }
    472472
    473473    private static IEnumerable<Resource> GetAssignedResourcesForJob(Guid jobId) {
    474474      var assignedJobResources = HiveServiceLocator.Instance.CallHiveService(s => s.GetAssignedResourcesForJob(jobId));
    475       return HiveAdminClient.Instance.Resources.Where(x => assignedJobResources.Select(y => y.ResourceId).Contains(x.Id));
     475      return HiveClient.Instance.Resources.Where(x => assignedJobResources.Select(y => y.ResourceId).Contains(x.Id));
    476476    }
    477477
     
    581581      resourceAncestors.Clear();
    582582      resourceDescendants.Clear();
    583       var resources = HiveAdminClient.Instance.Resources;
     583      var resources = HiveClient.Instance.Resources;
    584584
    585585      foreach (var r in resources) {
  • branches/HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelectorDialog.cs

    r15642 r15658  
    8080    #region Overrides
    8181    protected override void OnLoad(EventArgs e) {
    82       HiveAdminClient.Instance.Refreshing += HiveAdminClient_Instance_Refreshing;
    83       HiveAdminClient.Instance.Refreshed += HiveAdminClient_Instance_Refreshed;
     82      HiveClient.Instance.Refreshing += HiveClient_Instance_Refreshing;
     83      HiveClient.Instance.Refreshed += HiveClient_Instance_Refreshed;
    8484      base.OnLoad(e);
    8585    }
    8686
    8787    protected override void OnClosing(CancelEventArgs e) {
    88       HiveAdminClient.Instance.Refreshed -= HiveAdminClient_Instance_Refreshed;
    89       HiveAdminClient.Instance.Refreshing -= HiveAdminClient_Instance_Refreshing;
     88      HiveClient.Instance.Refreshed -= HiveClient_Instance_Refreshed;
     89      HiveClient.Instance.Refreshing -= HiveClient_Instance_Refreshing;
    9090      base.OnClosing(e);
    9191    }
     
    9393
    9494    #region Event Handlers
    95     private void HiveAdminClient_Instance_Refreshing(object sender, EventArgs e) {
    96       if (InvokeRequired) Invoke((Action<object, EventArgs>)HiveAdminClient_Instance_Refreshing, sender, e);
     95    private void HiveClient_Instance_Refreshing(object sender, EventArgs e) {
     96      if (InvokeRequired) Invoke((Action<object, EventArgs>)HiveClient_Instance_Refreshing, sender, e);
    9797      else {
    9898        var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>();
     
    102102    }
    103103
    104     private void HiveAdminClient_Instance_Refreshed(object sender, EventArgs e) {
    105       if (InvokeRequired) Invoke((Action<object, EventArgs>)HiveAdminClient_Instance_Refreshed, sender, e);
     104    private void HiveClient_Instance_Refreshed(object sender, EventArgs e) {
     105      if (InvokeRequired) Invoke((Action<object, EventArgs>)HiveClient_Instance_Refreshed, sender, e);
    106106      else {
    107107        var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>();
     
    129129
    130130      await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
    131         action: () => UpdateProjects(),
     131        action: () => UpdateInstance(),
    132132        finallyCallback: () => updatingProjects = false);
    133133    }
     
    151151
    152152    #region Helpers
     153    private void UpdateInstance() {
     154      HiveClient.Instance.Refresh();
     155    }
     156
    153157    private void UpdateProjects() {
    154       HiveAdminClient.Instance.Refresh();
     158      HiveClient.Instance.RefreshProjectsAndResources();
    155159      hiveResourceSelector.JobId = jobId;
    156160      hiveResourceSelector.ProjectId = projectId;
  • branches/HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveAdminClient.cs

    r15576 r15658  
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
     26using System.Collections.Generic;
    2627
    2728namespace HeuristicLab.Clients.Hive {
     
    3637    }
    3738
     39    #region Properties
    3840    private IItemList<Resource> resources;
    3941    public IItemList<Resource> Resources {
     
    6264    }
    6365
     66    #endregion
     67
    6468    #region Events
    6569    public event EventHandler Refreshing;
     
    8690
    8791        HiveServiceLocator.Instance.CallHiveService(service => {
    88           service.GetSlaveGroups().ForEach(g => resources.Add(g));
    89           service.GetSlaves().ForEach(s => resources.Add(s));
     92          service.GetSlaveGroupsForAdministration().ForEach(g => resources.Add(g));
     93          service.GetSlavesForAdministration().ForEach(s => resources.Add(s));
    9094          service.GetProjectsForAdministration().ForEach(p => projects.Add(p));
    9195        });
     
    174178      }
    175179    }
     180
     181    #region
     182    public bool CheckAccessToAdminAreaGranted() {
     183      if(projects != null) {
     184        return projects.Count > 0;
     185      } else {
     186        bool accessGranted = false;
     187        HiveServiceLocator.Instance.CallHiveService(s => {
     188          accessGranted = s.CheckAccessToAdminAreaGranted();
     189        });
     190        return accessGranted;
     191      }
     192    }
     193    #endregion
    176194  }
    177195}
  • branches/HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveClient.cs

    r15642 r15658  
    5757    }
    5858
     59    private IItemList<Project> projects;
     60    public IItemList<Project> Projects {
     61      get { return projects; }
     62    }
     63
     64    private IItemList<Resource> resources;
     65    public IItemList<Resource> Resources {
     66      get { return resources; }
     67    }
     68
     69
    5970    private List<Plugin> onlinePlugins;
    6071    public List<Plugin> OnlinePlugins {
     
    93104
    94105      try {
     106        projects = new ItemList<Project>();
     107        resources = new ItemList<Resource>();
    95108        jobs = new HiveItemCollection<RefreshableJob>();
    96         var jobsLoaded = HiveServiceLocator.Instance.CallHiveService<IEnumerable<Job>>(s => s.GetJobs());
    97 
    98         foreach (var j in jobsLoaded) {
    99           jobs.Add(new RefreshableJob(j));
    100         }
     109
     110        HiveServiceLocator.Instance.CallHiveService(service => {
     111          service.GetProjects().ForEach(p => projects.Add(p));
     112          service.GetSlaveGroups().ForEach(g => resources.Add(g));
     113          service.GetSlaves().ForEach(s => resources.Add(s));
     114          service.GetJobs().ForEach(p => jobs.Add(new RefreshableJob(p)));
     115        });
    101116      }
    102117      catch {
    103118        jobs = null;
     119        projects = null;
     120        resources = null;
    104121        throw;
    105122      }
    106123      finally {
     124        OnRefreshed();
     125      }
     126    }
     127
     128    public void RefreshProjectsAndResources() {
     129      OnRefreshing();
     130
     131      try {
     132        projects = new ItemList<Project>();
     133        resources = new ItemList<Resource>();
     134
     135        HiveServiceLocator.Instance.CallHiveService(service => {
     136          service.GetProjects().ForEach(p => projects.Add(p));
     137          service.GetSlaveGroups().ForEach(g => resources.Add(g));
     138          service.GetSlaves().ForEach(s => resources.Add(s));
     139        });
     140      } catch {
     141        projects = null;
     142        resources = null;
     143        throw;
     144      } finally {
    107145        OnRefreshed();
    108146      }
     
    124162      }, null);
    125163    }
     164   
    126165    #endregion
    127166
  • branches/HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/ServiceClients/HiveServiceClient.cs

    r15630 r15658  
    24922492        System.Collections.Generic.List<HeuristicLab.Clients.Hive.SlaveGroup> GetSlaveGroups();
    24932493       
     2494        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/GetSlavesForAdministration", ReplyAction="http://tempuri.org/IHiveService/GetSlavesForAdministrationResponse")]
     2495        System.Collections.Generic.List<HeuristicLab.Clients.Hive.Slave> GetSlavesForAdministration();
     2496       
     2497        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/GetSlaveGroupsForAdministration", ReplyAction="http://tempuri.org/IHiveService/GetSlaveGroupsForAdministrationResponse")]
     2498        System.Collections.Generic.List<HeuristicLab.Clients.Hive.SlaveGroup> GetSlaveGroupsForAdministration();
     2499       
    24942500        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/UpdateSlave", ReplyAction="http://tempuri.org/IHiveService/UpdateSlaveResponse")]
    24952501        void UpdateSlave(HeuristicLab.Clients.Hive.Slave slave);
     
    25392545        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/GetUserGroupTree", ReplyAction="http://tempuri.org/IHiveService/GetUserGroupTreeResponse")]
    25402546        System.Collections.Generic.Dictionary<System.Guid, System.Collections.Generic.List<System.Guid>> GetUserGroupTree();
     2547       
     2548        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/CheckAccessToAdminAreaGranted", ReplyAction="http://tempuri.org/IHiveService/CheckAccessToAdminAreaGrantedResponse")]
     2549        bool CheckAccessToAdminAreaGranted();
    25412550       
    25422551        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/GetUserPriorities", ReplyAction="http://tempuri.org/IHiveService/GetUserPrioritiesResponse")]
     
    28232832        }
    28242833       
     2834        public System.Collections.Generic.List<HeuristicLab.Clients.Hive.Slave> GetSlavesForAdministration()
     2835        {
     2836            return base.Channel.GetSlavesForAdministration();
     2837        }
     2838       
     2839        public System.Collections.Generic.List<HeuristicLab.Clients.Hive.SlaveGroup> GetSlaveGroupsForAdministration()
     2840        {
     2841            return base.Channel.GetSlaveGroupsForAdministration();
     2842        }
     2843       
    28252844        public void UpdateSlave(HeuristicLab.Clients.Hive.Slave slave)
    28262845        {
     
    29032922        }
    29042923       
     2924        public bool CheckAccessToAdminAreaGranted()
     2925        {
     2926            return base.Channel.CheckAccessToAdminAreaGranted();
     2927        }
     2928       
    29052929        public System.Collections.Generic.List<HeuristicLab.Clients.Hive.UserPriority> GetUserPriorities()
    29062930        {
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/AssignedProjectResourceDao.cs

    r15628 r15658  
    7777    public IEnumerable<Guid> GetAllGrantedResourceIdsByProjectId(Guid projectId) {
    7878      return DataContext.ExecuteQuery<Guid>(GetAllGrantedResourceIdsByProjectIdQueryString, projectId);
     79    }
     80
     81    public IEnumerable<Resource> GetAllGrantedResourcesByProjectIds(IEnumerable<Guid> projectIds) {
     82      string paramProjectIds = string.Join(",", projectIds.ToList().Select(x => string.Format("'{0}'", x)));
     83      if (!string.IsNullOrWhiteSpace(paramProjectIds)) {
     84        string queryString = string.Format(GetAllGrantedResourcesByProjectIdsQueryString, paramProjectIds);
     85        return DataContext.ExecuteQuery<Resource>(queryString);
     86      }
     87      return Enumerable.Empty<Resource>();
    7988    }
    8089
     
    173182    WHERE apr.ProjectId = '{0}'
    174183    ";
     184    private const string GetAllGrantedResourcesByProjectIdsQueryString = @"
     185      WITH rtree AS
     186      (
     187        SELECT ResourceId, ParentResourceId
     188        FROM [Resource]
     189        UNION ALL
     190        SELECT rt.ResourceId, r.ParentResourceId
     191        FROM [Resource] r
     192        JOIN rtree rt ON rt.ParentResourceId = r.ResourceId
     193      )
     194      SELECT res.*
     195      FROM rtree, [AssignedProjectResource] apr, [Resource] res
     196      WHERE rtree.ParentResourceId = apr.ResourceId
     197      AND rtree.ResourceId = res.ResourceId
     198      AND apr.ProjectId IN ({0})
     199      UNION
     200      SELECT res.*
     201      FROM [AssignedProjectResource] apr, [Resource] res
     202      WHERE apr.ResourceId = res.ResourceId
     203      AND apr.ProjectId IN ({0})
     204    ";
    175205    private const string GetAllGrantedResourceIdsOfOwnedParentProjectsQueryString = @"
    176206      WITH pbranch AS
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/HeuristicLab.Services.Hive.DataAccess-3.3.csproj

    r15644 r15658  
    110110    <Compile Include="Daos\HiveStatistics\DimClientDao.cs" />
    111111    <Compile Include="Daos\HiveStatistics\DimJobDao.cs" />
     112    <Compile Include="Daos\HiveStatistics\DimProjectDao.cs" />
    112113    <Compile Include="Daos\HiveStatistics\DimTimeDao.cs" />
    113114    <Compile Include="Daos\HiveStatistics\DimUserDao.cs" />
    114115    <Compile Include="Daos\HiveStatistics\FactClientInfoDao.cs" />
     116    <Compile Include="Daos\HiveStatistics\FactProjectInfoDao.cs" />
    115117    <Compile Include="Daos\HiveStatistics\FactTaskDao.cs" />
    116118    <Compile Include="Daos\JobDao.cs" />
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs

    r15644 r15658  
    11291129    public IEnumerable<DT.Slave> GetSlaves() {
    11301130      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    1131       bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator);
    11321131      var pm = PersistenceManager;
    11331132      using (new PerformanceLogger("GetSlaves")) {
    11341133        var slaveDao = pm.SlaveDao;
    1135         //var projectPermissionDao = pm.ProjectPermissionDao;
     1134        var projectDao = pm.ProjectDao;
     1135        var assignedProjectResourceDao = pm.AssignedProjectResourceDao;
     1136
     1137        // collect user information
    11361138        var currentUserId = UserManager.CurrentUserId;
    1137         return pm.UseTransaction(() => {
    1138             return slaveDao.GetAll().ToList()
    1139               .Where( x => isAdministrator
    1140               || x.OwnerUserId == null
    1141               || x.OwnerUserId == currentUserId)
     1139        var userAndGroupIds = new List<Guid> { currentUserId };
     1140        userAndGroupIds.AddRange(UserManager.GetUserGroupIdsOfUser(currentUserId));
     1141
     1142        return pm.UseTransaction(() => {
     1143          var slaves = slaveDao.GetAll()
     1144            .Select(x => x.ToDto())
     1145            .ToList();
     1146          var grantedProjectIds = projectDao.GetUsageGrantedProjectsForUser(userAndGroupIds)
     1147            .Select(x => x.ProjectId)
     1148            .ToList();
     1149          var grantedResourceIds = assignedProjectResourceDao.GetAllGrantedResourcesByProjectIds(grantedProjectIds)
     1150            .Select(x => x.ResourceId)
     1151            .ToList();
     1152
     1153          return slaves
     1154            .Where(x => grantedResourceIds.Contains(x.Id))
     1155            .ToList();
     1156        });
     1157      }
     1158    }
     1159
     1160    public IEnumerable<DT.SlaveGroup> GetSlaveGroups() {
     1161      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
     1162      var pm = PersistenceManager;
     1163      using (new PerformanceLogger("GetSlaveGroups")) {
     1164        var slaveGroupDao = pm.SlaveGroupDao;
     1165        var projectDao = pm.ProjectDao;
     1166        var assignedProjectResourceDao = pm.AssignedProjectResourceDao;
     1167
     1168        // collect user information
     1169        var currentUserId = UserManager.CurrentUserId;
     1170        var userAndGroupIds = new List<Guid> { currentUserId };
     1171        userAndGroupIds.AddRange(UserManager.GetUserGroupIdsOfUser(currentUserId));
     1172
     1173        return pm.UseTransaction(() => {
     1174          var slaveGroups = slaveGroupDao.GetAll()
     1175            .Select(x => x.ToDto())
     1176            .ToList();
     1177          var grantedProjectIds = projectDao.GetUsageGrantedProjectsForUser(userAndGroupIds)
     1178            .Select(x => x.ProjectId)
     1179            .ToList();
     1180          var grantedResourceIds = assignedProjectResourceDao.GetAllGrantedResourcesByProjectIds(grantedProjectIds)
     1181            .Select(x => x.ResourceId)
     1182            .ToList();
     1183
     1184          return slaveGroups
     1185            .Where(x => grantedResourceIds.Contains(x.Id))
     1186            .ToList();
     1187        });
     1188      }
     1189    }
     1190
     1191    public IEnumerable<DT.Slave> GetSlavesForAdministration() {
     1192      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
     1193      bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator);
     1194      var pm = PersistenceManager;
     1195      using (new PerformanceLogger("GetSlavesForAdministration")) {
     1196        var slaveDao = pm.SlaveDao;
     1197        var currentUserId = UserManager.CurrentUserId;
     1198
     1199        if (isAdministrator) {
     1200          return pm.UseTransaction(() => {
     1201            return slaveDao.GetAll()
    11421202              .Select(x => x.ToDto())
    11431203              .ToList();
    1144           //var projectPermissions = projectPermissionDao.GetAll();
    1145           //return slaveDao.GetAll().ToList()
    1146           //  .Where(x => isAdministrator
    1147           //    || x.OwnerUserId == null
    1148           //    || x.OwnerUserId == currentUserId
    1149           //    || UserManager.VerifyUser(currentUserId, projectPermissions
    1150           //        //.Where(y => y.ResourceId == x.ResourceId)
    1151           //        .Select(z => z.GrantedUserId)
    1152           //        .ToList())
    1153           //    )
    1154           //  .Select(x => x.ToDto())
    1155           //  .ToList();
    1156         });
    1157       }
    1158     }
    1159 
    1160     public IEnumerable<DT.SlaveGroup> GetSlaveGroups() {
     1204          });
     1205        } else {
     1206          var slaves = slaveDao.GetAll()
     1207            .Select(x => x.ToDto())
     1208            .ToList();
     1209          var projectDao = pm.ProjectDao;
     1210          var assignedProjectResourceDao = pm.AssignedProjectResourceDao;
     1211          var projects = projectDao.GetAdministrationGrantedProjectsForUser(currentUserId).ToList();
     1212          var resourceIds = assignedProjectResourceDao
     1213            .GetAllGrantedResourcesByProjectIds(projects.Select(x => x.ProjectId).ToList())
     1214            .Select(x => x.ResourceId)
     1215            .ToList();
     1216
     1217          return slaves
     1218            .Where(x => resourceIds.Contains(x.Id))
     1219            .ToList();
     1220        }
     1221      }
     1222    }
     1223
     1224    public IEnumerable<DT.SlaveGroup> GetSlaveGroupsForAdministration() {
    11611225      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    11621226      bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator);
    11631227      var pm = PersistenceManager;
    1164       using (new PerformanceLogger("GetSlaveGroups")) {
     1228      using (new PerformanceLogger("GetSlaveGroupsForAdministration")) {
    11651229        var slaveGroupDao = pm.SlaveGroupDao;
    1166         var projectPermissionDao = pm.ProjectPermissionDao;
    11671230        var currentUserId = UserManager.CurrentUserId;
    1168         return pm.UseTransaction(() => {
    1169           //var projectPermissions = projectPermissionDao.GetAll();
    1170           return slaveGroupDao.GetAll().ToList()
    1171             .Where(x => isAdministrator
    1172               || x.OwnerUserId == null
    1173               || x.OwnerUserId == currentUserId
    1174               //|| UserManager.VerifyUser(currentUserId, projectPermissions
    1175               //    //.Where(y => y.ResourceId == x.ResourceId)
    1176               //    .Select(z => z.GrantedUserId)
    1177               //    .ToList())
    1178              )
     1231
     1232        if (isAdministrator) {
     1233          return pm.UseTransaction(() => {
     1234            return slaveGroupDao.GetAll()
     1235              .Select(x => x.ToDto())
     1236              .ToList();
     1237          });
     1238        } else {
     1239          var slaveGroups = slaveGroupDao.GetAll()
    11791240            .Select(x => x.ToDto())
    11801241            .ToList();
    1181         });
     1242          var projectDao = pm.ProjectDao;
     1243          var assignedProjectResourceDao = pm.AssignedProjectResourceDao;
     1244          var projects = projectDao.GetAdministrationGrantedProjectsForUser(currentUserId).ToList();
     1245          var resourceIds = assignedProjectResourceDao
     1246            .GetAllGrantedResourcesByProjectIds(projects.Select(x => x.ProjectId).ToList())
     1247            .Select(x => x.ResourceId)
     1248            .ToList();
     1249
     1250          return slaveGroups
     1251            .Where(x => resourceIds.Contains(x.Id))
     1252            .ToList();
     1253        }
    11821254      }
    11831255    }
     
    11851257    public void UpdateSlave(DT.Slave slaveDto) {
    11861258      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
     1259      AuthorizationManager.AuthorizeForResourceAdministration(slaveDto.Id);
    11871260      var pm = PersistenceManager;
    11881261      using (new PerformanceLogger("UpdateSlave")) {
     
    12021275    public void UpdateSlaveGroup(DT.SlaveGroup slaveGroupDto) {
    12031276      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
     1277      AuthorizationManager.AuthorizeForResourceAdministration(slaveGroupDto.Id);
    12041278      var pm = PersistenceManager;
    12051279      using (new PerformanceLogger("UpdateSlaveGroup")) {
     
    14051479
    14061480      return userGroupTree;
     1481    }
     1482
     1483    public bool CheckAccessToAdminAreaGranted() {
     1484      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
     1485      bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator);
     1486      var pm = PersistenceManager;
     1487      using(new PerformanceLogger("CheckAccessToAdminAreaGranted")) {
     1488        if (isAdministrator) {
     1489          return true;
     1490        } else {
     1491          var projectDao = pm.ProjectDao;
     1492          var currentUserId = UserManager.CurrentUserId;
     1493          return projectDao.GetAdministrationGrantedProjectsForUser(currentUserId).Any();
     1494        }
     1495      }
    14071496    }
    14081497    #endregion
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/ServiceContracts/IHiveService.cs

    r15644 r15658  
    210210
    211211    [OperationContract]
     212    IEnumerable<Slave> GetSlavesForAdministration();
     213
     214    [OperationContract]
     215    IEnumerable<SlaveGroup> GetSlaveGroupsForAdministration();
     216
     217    [OperationContract]
    212218    void UpdateSlave(Slave slave);
    213219
     
    260266    [OperationContract]
    261267    Dictionary<Guid, HashSet<Guid>> GetUserGroupTree();
     268
     269    [OperationContract]
     270    bool CheckAccessToAdminAreaGranted();
    262271    #endregion
    263272
Note: See TracChangeset for help on using the changeset viewer.