Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/09/18 07:56:01 (6 years ago)
Author:
jzenisek
Message:

#2839 worked on HiveAdministrator:

  • corrected and modified CRUD operations
  • improved usability by providing detailed state information, adding dialogs etc.
Location:
branches/HiveProjectManagement/HeuristicLab.Clients.Hive/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveAdminClient.cs

    r15658 r15742  
    2525using HeuristicLab.Core;
    2626using System.Collections.Generic;
     27using System.Linq;
    2728
    2829namespace HeuristicLab.Clients.Hive {
     
    6465    }
    6566
     67    private Dictionary<Guid, HashSet<Project>> projectAncestors;
     68    public Dictionary<Guid, HashSet<Project>> ProjectAncestors {
     69      get { return projectAncestors; }
     70    }
     71
     72    private Dictionary<Guid, HashSet<Project>> projectDescendants;
     73    public Dictionary<Guid, HashSet<Project>> ProjectDescendants {
     74      get { return projectDescendants; }
     75    }
     76
     77    private Dictionary<Guid, HashSet<Resource>> resourceAncestors;
     78    public Dictionary<Guid, HashSet<Resource>> ResourceAncestors {
     79      get { return ResourceAncestors; }
     80    }
     81
     82    private Dictionary<Guid, HashSet<Resource>> resourceDescendants;
     83    public Dictionary<Guid, HashSet<Resource>> ResourceDescendants {
     84      get { return ResourceDescendants; }
     85    }
     86
     87
    6688    #endregion
    6789
     
    89111        projects = new ItemList<Project>();
    90112
     113        projectAncestors = new Dictionary<Guid, HashSet<Project>>();
     114        projectDescendants = new Dictionary<Guid, HashSet<Project>>();
     115        resourceAncestors = new Dictionary<Guid, HashSet<Resource>>();
     116        resourceDescendants = new Dictionary<Guid, HashSet<Resource>>();
     117
    91118        HiveServiceLocator.Instance.CallHiveService(service => {
    92119          service.GetSlaveGroupsForAdministration().ForEach(g => resources.Add(g));
     
    94121          service.GetProjectsForAdministration().ForEach(p => projects.Add(p));
    95122        });
     123
     124        UpdateResourceGenealogy();
     125        UpdateProjectGenealogy();
    96126      }
    97127      catch {
     
    100130      finally {
    101131        OnRefreshed();
     132      }
     133    }
     134
     135    private void UpdateResourceGenealogy() {
     136      resourceAncestors.Clear();
     137      resourceDescendants.Clear();
     138
     139      foreach (var r in resources) {
     140        resourceAncestors.Add(r.Id, new HashSet<Resource>());
     141        resourceDescendants.Add(r.Id, new HashSet<Resource>());
     142      }
     143
     144      foreach (var r in resources) {
     145        var parentResourceId = r.ParentResourceId;
     146        while (parentResourceId != null) {
     147          var parent = resources.SingleOrDefault(x => x.Id == parentResourceId);
     148          if (parent != null) {
     149            resourceAncestors[r.Id].Add(parent);
     150            resourceDescendants[parent.Id].Add(r);
     151            parentResourceId = parent.ParentResourceId;
     152          } else {
     153            parentResourceId = null;
     154          }
     155        }
     156      }
     157    }
     158
     159    private void UpdateProjectGenealogy() {
     160      projectAncestors.Clear();
     161      projectDescendants.Clear();
     162
     163      foreach (var p in projects) {
     164        projectAncestors.Add(p.Id, new HashSet<Project>());
     165        projectDescendants.Add(p.Id, new HashSet<Project>());
     166      }
     167
     168      foreach (var p in projects) {
     169        var parentProjectId = p.ParentProjectId;
     170        while (parentProjectId != null) {
     171          var parent = projects.SingleOrDefault(x => x.Id == parentProjectId);
     172          if (parent != null) {
     173            projectAncestors[p.Id].Add(parent);
     174            projectDescendants[parent.Id].Add(p);
     175            parentProjectId = parent.ParentProjectId;
     176          } else {
     177            parentProjectId = null;
     178          }
     179        }
    102180      }
    103181    }
     
    179257    }
    180258
    181     #region
     259    #region Helper
    182260    public bool CheckAccessToAdminAreaGranted() {
    183261      if(projects != null) {
     
    191269      }
    192270    }
     271
     272    public bool CheckOwnershipOfResource(Resource res, Guid userId) {
     273      if (res == null || userId == Guid.Empty) return false;
     274
     275      if (res.OwnerUserId == userId) {
     276        return true;
     277      } else if(resourceAncestors.ContainsKey(res.Id)) {
     278        return resourceAncestors[res.Id].Where(x => x.OwnerUserId == userId).Any();
     279      }
     280
     281      return false;
     282    }
     283
     284    public bool CheckOwnershipOfProject(Project pro, Guid userId) {
     285      if (pro == null || userId == Guid.Empty) return false;
     286
     287      if (pro.OwnerUserId == userId) {
     288        return true;
     289      } else if (projectAncestors.ContainsKey(pro.Id)) {
     290        return projectAncestors[pro.Id].Where(x => x.OwnerUserId == userId).Any();
     291      }
     292
     293      return false;
     294    }
     295
     296    public bool CheckOwnershipOfParentProject(Project pro, Guid userId) {
     297      if (pro == null || userId == Guid.Empty) return false;
     298
     299      if(projectAncestors.ContainsKey(pro.Id)) {
     300        return projectAncestors[pro.Id].Where(x => x.OwnerUserId == userId).Any();
     301      }
     302
     303      return false;
     304    }
    193305    #endregion
    194306  }
  • branches/HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveClient.cs

    r15658 r15742  
    169169      if (item.Id == Guid.Empty) {
    170170        if (item is RefreshableJob) {
    171           HiveClient.Instance.UploadJob((RefreshableJob)item, cancellationToken);
     171          item.Id = HiveClient.Instance.UploadJob((RefreshableJob)item, cancellationToken);
    172172        }
    173173        if (item is JobPermission) {
     
    180180        }
    181181        if (item is Project) {
    182           HiveServiceLocator.Instance.CallHiveService(s => s.AddProject((Project)item));
     182          item.Id = HiveServiceLocator.Instance.CallHiveService(s => s.AddProject((Project)item));
    183183        }
    184184      } else {
     
    302302    private static object jobCountLocker = new object();
    303303    private static object pluginLocker = new object();
    304     private void UploadJob(RefreshableJob refreshableJob, CancellationToken cancellationToken) {
     304    private Guid UploadJob(RefreshableJob refreshableJob, CancellationToken cancellationToken) {
    305305      try {
    306306        refreshableJob.IsProgressing = true;
     
    347347        refreshableJob.Progress.Finish();
    348348      }
     349      return (refreshableJob.Job != null) ? refreshableJob.Job.Id : Guid.Empty;
    349350    }
    350351
Note: See TracChangeset for help on using the changeset viewer.