Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/26/18 08:51:30 (7 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/HeuristicLab.Clients.Hive.Administrator/3.3
Files:
4 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 };
Note: See TracChangeset for help on using the changeset viewer.