Ignore:
Timestamp:
01/26/18 08:51:30 (3 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)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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  }
Note: See TracChangeset for help on using the changeset viewer.