Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15379


Ignore:
Timestamp:
09/25/17 15:36:54 (7 years ago)
Author:
jkarder
Message:

#2839:

  • added Project and ProjectPermission DAOs and service methods
  • made Project.EndDate nullable
Location:
branches/HiveProjectManagement
Files:
2 added
9 edited
2 moved

Legend:

Unmodified
Added
Removed
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectPermissionDao.cs

    r15378 r15379  
    2626
    2727namespace HeuristicLab.Services.Hive.DataAccess.Daos {
    28   public class ResourcePermissionDao : GenericDao<Guid, ResourcePermission> {
    29     public ResourcePermissionDao(DataContext dataContext) : base(dataContext) { }
     28  public class ProjectPermissionDao : GenericDao<Guid, ProjectPermission> {
     29    public ProjectPermissionDao(DataContext dataContext) : base(dataContext) { }
    3030
    31     public override ResourcePermission GetById(Guid id) {
     31    public override ProjectPermission GetById(Guid id) {
    3232      throw new NotImplementedException();
    3333    }
    3434
    35     public IEnumerable<ResourcePermission> GetByResourceId(Guid id) {
    36       return GetByResourceIdGetByIdQuery(DataContext, id);
     35    public IEnumerable<ProjectPermission> GetByProjectId(Guid id) {
     36      return GetByProjectIdGetByIdQuery(DataContext, id);
    3737    }
    3838
    39     public void DeleteByResourceAndGrantedUserId(Guid resourceId, IEnumerable<Guid> grantedUserId) {
     39    public void DeleteByProjectAndGrantedUserId(Guid projectId, IEnumerable<Guid> grantedUserId) {
    4040      string paramIds = string.Join(",", grantedUserId.Select(x => string.Format("'{0}'", x)));
    4141      if (!string.IsNullOrWhiteSpace(paramIds)) {
    42         string query = string.Format(DeleteByGrantedUserQuery, resourceId, paramIds);
     42        string query = string.Format(DeleteByGrantedUserQuery, projectId, paramIds);
    4343        DataContext.ExecuteCommand(query);
    4444      }
     
    4646
    4747    #region Compiled queries
    48     private static readonly Func<DataContext, Guid, IEnumerable<ResourcePermission>> GetByResourceIdGetByIdQuery =
    49       CompiledQuery.Compile((DataContext db, Guid resourceId) =>
    50         from resourcePermission in db.GetTable<ResourcePermission>()
    51         where resourcePermission.ResourceId == resourceId
    52         select resourcePermission);
     48    private static readonly Func<DataContext, Guid, IEnumerable<ProjectPermission>> GetByProjectIdGetByIdQuery =
     49      CompiledQuery.Compile((DataContext db, Guid projectId) =>
     50        from projectPermission in db.GetTable<ProjectPermission>()
     51        where projectPermission.ProjectId == projectId
     52        select projectPermission);
    5353    #endregion
    5454
    5555    #region String queries
    5656    private const string DeleteByGrantedUserQuery =
    57       @"DELETE FROM [ResourcePermission]
    58          WHERE ResourceId = '{0}'
     57      @"DELETE FROM [ProjectPermission]
     58         WHERE ProjectId = '{0}'
    5959           AND GrantedUserId IN ({1});";
    6060    #endregion
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/HeuristicLab.Services.Hive.DataAccess-3.3.csproj

    r12878 r15379  
    118118    <Compile Include="Daos\PluginDao.cs" />
    119119    <Compile Include="Daos\PluginDataDao.cs" />
     120    <Compile Include="Daos\ProjectDao.cs" />
     121    <Compile Include="Daos\ProjectPermissionDao.cs" />
    120122    <Compile Include="Daos\RequiredPluginDao.cs" />
    121123    <Compile Include="Daos\ResourceDao.cs" />
    122     <Compile Include="Daos\ResourcePermissionDao.cs" />
    123124    <Compile Include="Daos\SlaveDao.cs" />
    124125    <Compile Include="Daos\SlaveGroupDao.cs" />
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml

    r15378 r15379  
    265265      <Column Name="OwnerUserId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" CanBeNull="false" />
    266266      <Column Name="StartDate" Type="System.DateTime" DbType="DateTime NOT NULL" CanBeNull="false" />
    267       <Column Name="EndDate" Type="System.DateTime" DbType="DateTime" CanBeNull="false" />
     267      <Column Name="EndDate" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
    268268      <Association Name="Project_AssignedResource" Member="AssignedResources" ThisKey="ProjectId" OtherKey="ProjectId" Type="AssignedResource" />
    269269      <Association Name="Project_Job" Member="Jobs" ThisKey="ProjectId" OtherKey="ProjectId" Type="Job" />
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.designer.cs

    r15378 r15379  
    56815681    private System.DateTime _StartDate;
    56825682   
    5683     private System.DateTime _EndDate;
     5683    private System.Nullable<System.DateTime> _EndDate;
    56845684   
    56855685    private EntitySet<AssignedResource> _AssignedResources;
     
    57115711    partial void OnStartDateChanging(System.DateTime value);
    57125712    partial void OnStartDateChanged();
    5713     partial void OnEndDateChanging(System.DateTime value);
     5713    partial void OnEndDateChanging(System.Nullable<System.DateTime> value);
    57145714    partial void OnEndDateChanged();
    57155715    #endregion
     
    58705870   
    58715871    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_EndDate", DbType="DateTime")]
    5872     public System.DateTime EndDate
     5872    public System.Nullable<System.DateTime> EndDate
    58735873    {
    58745874      get
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Interfaces/IPersistenceManager.cs

    r14185 r15379  
    3838    PluginDao PluginDao { get; }
    3939    PluginDataDao PluginDataDao { get; }
     40    ProjectDao ProjectDao { get; }
     41    ProjectPermissionDao ProjectPermissionDao { get; }
    4042    RequiredPluginDao RequiredPluginDao { get; }
    4143    ResourceDao ResourceDao { get; }
    42     ResourcePermissionDao ResourcePermissionDao { get; }
    4344    SlaveDao SlaveDao { get; }
    4445    SlaveGroupDao SlaveGroupDao { get; }
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Manager/PersistenceManager.cs

    r14185 r15379  
    7373    }
    7474
     75    private ProjectDao projectDao;
     76    public ProjectDao ProjectDao {
     77      get { return projectDao ?? (projectDao = new ProjectDao(dataContext)); }
     78    }
     79
     80    private ProjectPermissionDao resourcePermissionDao;
     81    public ProjectPermissionDao ProjectPermissionDao {
     82      get { return resourcePermissionDao ?? (resourcePermissionDao = new ProjectPermissionDao(dataContext)); }
     83    }
     84
    7585    private RequiredPluginDao requiredPluginDao;
    7686    public RequiredPluginDao RequiredPluginDao {
     
    8191    public ResourceDao ResourceDao {
    8292      get { return resourceDao ?? (resourceDao = new ResourceDao(dataContext)); }
    83     }
    84 
    85     private ResourcePermissionDao resourcePermissionDao;
    86     public ResourcePermissionDao ResourcePermissionDao {
    87       get { return resourcePermissionDao ?? (resourcePermissionDao = new ResourcePermissionDao(dataContext)); }
    8893    }
    8994
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Converter.cs

    r14185 r15379  
    333333    #endregion
    334334
    335     #region ResourcePermission
    336     public static DT.ResourcePermission ToDto(this DA.ResourcePermission source) {
    337       if (source == null) return null;
    338       return new DT.ResourcePermission {
    339         ResourceId = source.ResourceId,
     335    #region Project
     336    public static DT.Project ToDto(this DA.Project source) {
     337      if (source == null) return null;
     338      return new DT.Project {
     339        Id = source.ProjectId,
     340        ParentProjectId = source.ParentProjectId,
     341        DateCreated = source.DateCreated,
     342        Name = source.Name,
     343        Description = source.Description,
     344        OwnerUserId = source.OwnerUserId,
     345        StartDate = source.StartDate,
     346        EndDate = source.EndDate
     347      };
     348    }
     349    public static DA.Project ToEntity(this DT.Project source) {
     350      if (source == null) return null;
     351      var result = new DA.Project();
     352      source.CopyToEntity(result);
     353      return result;
     354    }
     355    public static void CopyToEntity(this DT.Project source, DA.Project target) {
     356      if ((source == null) || (target == null)) return;
     357      target.ProjectId = source.Id;
     358      target.ParentProjectId = source.ParentProjectId;
     359      target.DateCreated = source.DateCreated;
     360      target.Name = source.Name;
     361      target.Description = source.Description;
     362      target.OwnerUserId = source.OwnerUserId;
     363      target.StartDate = source.StartDate;
     364      target.EndDate = source.EndDate;
     365    }
     366    #endregion
     367
     368    #region ProjectPermission
     369    public static DT.ProjectPermission ToDto(this DA.ProjectPermission source) {
     370      if (source == null) return null;
     371      return new DT.ProjectPermission {
     372        ProjectId = source.ProjectId,
    340373        GrantedUserId = source.GrantedUserId,
    341374        GrantedByUserId = source.GrantedByUserId
    342375      };
    343376    }
    344     public static DA.ResourcePermission ToEntity(this DT.ResourcePermission source) {
    345       if (source == null) return null;
    346       var result = new DA.ResourcePermission();
    347       source.CopyToEntity(result);
    348       return result;
    349     }
    350     public static void CopyToEntity(this DT.ResourcePermission source, DA.ResourcePermission target) {
    351       if ((source == null) || (target == null)) return;
    352       target.ResourceId = source.ResourceId;
     377    public static DA.ProjectPermission ToEntity(this DT.ProjectPermission source) {
     378      if (source == null) return null;
     379      var result = new DA.ProjectPermission();
     380      source.CopyToEntity(result);
     381      return result;
     382    }
     383    public static void CopyToEntity(this DT.ProjectPermission source, DA.ProjectPermission target) {
     384      if ((source == null) || (target == null)) return;
     385      target.ProjectId = source.ProjectId;
    353386      target.GrantedUserId = source.GrantedUserId;
    354387      target.GrantedByUserId = source.GrantedByUserId;
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/DataTransfer/ProjectPermission.cs

    r15378 r15379  
    2626  [DataContract]
    2727  [Serializable]
    28   public class ResourcePermission : HiveItem {
     28  public class ProjectPermission : HiveItem {
    2929    // info: this class is derived from HiveItem to simplify handling on the client side, altough it does not have a Id.
    3030    [DataMember]
    31     public Guid ResourceId { get; set; }
     31    public Guid ProjectId { get; set; }
    3232    [DataMember]
    3333    public Guid GrantedUserId { get; set; }
     
    3535    public Guid GrantedByUserId { get; set; }
    3636
    37     public ResourcePermission() { }
     37    public ProjectPermission() { }
    3838  }
    3939}
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj

    r12878 r15379  
    120120    <Compile Include="Converter.cs" />
    121121    <Compile Include="DataTransfer\Command.cs" />
     122    <Compile Include="DataTransfer\Project.cs" />
     123    <Compile Include="DataTransfer\ProjectPermission.cs" />
    122124    <Compile Include="DataTransfer\UserPriority.cs" />
    123     <Compile Include="DataTransfer\ResourcePermission.cs" />
    124125    <Compile Include="DataTransfer\Downtime.cs" />
    125126    <Compile Include="DataTransfer\Heartbeat.cs" />
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs

    r15358 r15379  
    532532          result = HeartbeatManager.ProcessHeartbeat(heartbeat);
    533533        }
    534       }
    535       catch (Exception ex) {
     534      } catch (Exception ex) {
    536535        DA.LogFactory.GetLogger(this.GetType().Namespace).Log(string.Format("Exception processing Heartbeat: {0}", ex));
    537536      }
     
    604603    #endregion
    605604
    606     #region ResourcePermission Methods
    607     public void GrantResourcePermissions(Guid resourceId, Guid[] grantedUserIds) {
    608       RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    609       var pm = PersistenceManager;
    610       using (new PerformanceLogger("GrantResourcePermissions")) {
    611         pm.UseTransaction(() => {
    612           var resource = AuthorizeForResource(pm, resourceId);
    613           var resourcePermissions = resource.ResourcePermissions.ToList();
     605    #region Project Methods
     606    public Guid AddProject(DT.Project projectDto) {
     607      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator);
     608      var pm = PersistenceManager;
     609      using (new PerformanceLogger("AddProject")) {
     610        var projectDao = pm.ProjectDao;
     611        return pm.UseTransaction(() => {
     612          var project = projectDao.Save(projectDto.ToEntity());
     613          pm.SubmitChanges();
     614          return project.ProjectId;
     615        });
     616      }
     617    }
     618
     619    public void UpdateProject(DT.Project projectDto) {
     620      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator);
     621      var pm = PersistenceManager;
     622      using (new PerformanceLogger("UpdateProject")) {
     623        var projectDao = pm.ProjectDao;
     624        pm.UseTransaction(() => {
     625          var project = projectDao.GetById(projectDto.Id);
     626          if (project != null) {
     627            projectDto.CopyToEntity(project);
     628          } else {
     629            projectDao.Save(projectDto.ToEntity());
     630          }
     631          pm.SubmitChanges();
     632        });
     633      }
     634    }
     635
     636    public void DeleteProject(Guid projectId) {
     637      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator);
     638      AuthorizationManager.AuthorizeForResourceAdministration(projectId);
     639      var pm = PersistenceManager;
     640      using (new PerformanceLogger("DeleteProject")) {
     641        var projectDao = pm.ProjectDao;
     642        pm.UseTransaction(() => {
     643          projectDao.Delete(projectId);
     644          pm.SubmitChanges();
     645        });
     646      }
     647    }
     648
     649    public DT.Project GetProject(Guid projectId) {
     650      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator);
     651      var pm = PersistenceManager;
     652      using (new PerformanceLogger("GetProject")) {
     653        var projectDao = pm.ProjectDao;
     654        return pm.UseTransaction(() => projectDao.GetById(projectId).ToDto());
     655      }
     656    }
     657
     658    public IEnumerable<DT.Project> GetProjects() {
     659      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
     660      bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator);
     661      var pm = PersistenceManager;
     662      using (new PerformanceLogger("GetProjects")) {
     663        var projectDao = pm.ProjectDao;
     664        var projectPermissionDao = pm.ProjectPermissionDao;
     665        var currentUserId = UserManager.CurrentUserId;
     666        return pm.UseTransaction(() => {
     667          var resourcePermissions = projectPermissionDao.GetAll();
     668          return projectDao.GetAll().ToList()
     669            .Where(x => isAdministrator
     670              || x.OwnerUserId == currentUserId
     671              || UserManager.VerifyUser(currentUserId, resourcePermissions
     672                  .Where(y => y.ProjectId == x.ProjectId)
     673                  .Select(z => z.GrantedUserId)
     674                  .ToList())
     675              )
     676            .Select(x => x.ToDto())
     677            .ToList();
     678        });
     679      }
     680    }
     681    #endregion
     682
     683    #region ProjectPermission Methods
     684    public void GrantProjectPermissions(Guid projectId, Guid[] grantedUserIds) {
     685      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
     686      var pm = PersistenceManager;
     687      using (new PerformanceLogger("GrantProjectPermissions")) {
     688        pm.UseTransaction(() => {
     689          var project = AuthorizeForProject(pm, projectId);
     690          var projectPermissions = project.ProjectPermissions.ToList();
    614691          foreach (var id in grantedUserIds) {
    615             if (resourcePermissions.All(x => x.GrantedUserId != id)) {
    616               resource.ResourcePermissions.Add(new DA.ResourcePermission {
     692            if (projectPermissions.All(x => x.GrantedUserId != id)) {
     693              project.ProjectPermissions.Add(new DA.ProjectPermission {
    617694                GrantedUserId = id,
    618695                GrantedByUserId = UserManager.CurrentUserId
     
    625702    }
    626703
    627     public void RevokeResourcePermissions(Guid resourceId, Guid[] grantedUserIds) {
    628       RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    629       var pm = PersistenceManager;
    630       using (new PerformanceLogger("RevokeResourcePermissions")) {
    631         var resourcePermissionDao = pm.ResourcePermissionDao;
    632         pm.UseTransaction(() => {
    633           AuthorizeForResource(pm, resourceId);
    634           resourcePermissionDao.DeleteByResourceAndGrantedUserId(resourceId, grantedUserIds);
    635           pm.SubmitChanges();
    636         });
    637       }
    638     }
    639 
    640     public IEnumerable<DT.ResourcePermission> GetResourcePermissions(Guid resourceId) {
    641       RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    642       var pm = PersistenceManager;
    643       using (new PerformanceLogger("GetResourcePermissions")) {
    644         var resourcePermissionDao = pm.ResourcePermissionDao;
    645         return pm.UseTransaction(() => resourcePermissionDao.GetByResourceId(resourceId)
     704    public void RevokeProjectPermissions(Guid projectId, Guid[] grantedUserIds) {
     705      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
     706      var pm = PersistenceManager;
     707      using (new PerformanceLogger("RevokeProjectPermissions")) {
     708        var projectPermissionDao = pm.ProjectPermissionDao;
     709        pm.UseTransaction(() => {
     710          AuthorizeForProject(pm, projectId);
     711          projectPermissionDao.DeleteByProjectAndGrantedUserId(projectId, grantedUserIds);
     712          pm.SubmitChanges();
     713        });
     714      }
     715    }
     716
     717    public IEnumerable<DT.ProjectPermission> GetProjectPermissions(Guid projectId) {
     718      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
     719      var pm = PersistenceManager;
     720      using (new PerformanceLogger("GetProjectPermissions")) {
     721        var projectPermissionDao = pm.ProjectPermissionDao;
     722        return pm.UseTransaction(() => projectPermissionDao.GetByProjectId(projectId)
    646723          .Select(x => x.ToDto())
    647724          .ToList()
     
    696773      using (new PerformanceLogger("GetSlaves")) {
    697774        var slaveDao = pm.SlaveDao;
    698         var resourcePermissionDao = pm.ResourcePermissionDao;
     775        var resourcePermissionDao = pm.ProjectPermissionDao;
    699776        var currentUserId = UserManager.CurrentUserId;
    700777        return pm.UseTransaction(() => {
     
    721798      using (new PerformanceLogger("GetSlaveGroups")) {
    722799        var slaveGroupDao = pm.SlaveGroupDao;
    723         var resourcePermissionDao = pm.ResourcePermissionDao;
     800        var resourcePermissionDao = pm.ProjectPermissionDao;
    724801        var currentUserId = UserManager.CurrentUserId;
    725802        return pm.UseTransaction(() => {
     
    9901067    }
    9911068
    992     private DA.Resource AuthorizeForResource(IPersistenceManager pm, Guid resourceId) {
    993       var resourceDao = pm.ResourceDao;
    994       var resource = resourceDao.GetById(resourceId);
    995       if (resource == null) throw new SecurityException("Not authorized");
    996       if (resource.OwnerUserId != UserManager.CurrentUserId
     1069    private DA.Project AuthorizeForProject(IPersistenceManager pm, Guid projectId) {
     1070      var projectDao = pm.ProjectDao;
     1071      var project = projectDao.GetById(projectId);
     1072      if (project == null) throw new SecurityException("Not authorized");
     1073      if (project.OwnerUserId != UserManager.CurrentUserId
    9971074          && !RoleVerifier.IsInRole(HiveRoles.Administrator)) {
    9981075        throw new SecurityException("Not authorized");
    9991076      }
    1000       return resource;
     1077      return project;
    10011078    }
    10021079    #endregion
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/ServiceContracts/IHiveService.cs

    r14185 r15379  
    132132    #endregion
    133133
     134    #region Project Methods
     135    [OperationContract]
     136    Guid AddProject(Project projectDto);
     137
     138    [OperationContract]
     139    void UpdateProject(Project projectDto);
     140
     141    [OperationContract]
     142    void DeleteProject(Guid projectId);
     143
     144    [OperationContract]
     145    Project GetProject(Guid projectId);
     146
     147    [OperationContract]
     148    IEnumerable<Project> GetProjects();
     149    #endregion
     150
    134151    #region ResourcePermission Methods
    135152    [OperationContract]
     
    140157
    141158    [OperationContract]
    142     IEnumerable<ResourcePermission> GetResourcePermissions(Guid resourceId);
     159    IEnumerable<ProjectPermission> GetResourcePermissions(Guid resourceId);
    143160    #endregion
    144161
Note: See TracChangeset for help on using the changeset viewer.