Esempio n. 1
0
 /// <summary>
 /// Sets the permissions for a experiment. makes sure that only one permission per user exists.
 /// </summary>
 public void SetHiveExperimentPermission(Guid hiveExperimentId, Guid grantedByUserId, Guid grantedUserId, Permission permission)
 {
     using (var db = CreateContext()) {
         HiveExperimentPermission hiveExperimentPermission = db.HiveExperimentPermissions.SingleOrDefault(x => x.HiveExperimentId == hiveExperimentId && x.GrantedUserId == grantedUserId);
         if (hiveExperimentPermission != null)
         {
             if (permission == Permission.NotAllowed)
             {
                 // not allowed, delete
                 db.HiveExperimentPermissions.DeleteOnSubmit(hiveExperimentPermission);
             }
             else
             {
                 // update
                 hiveExperimentPermission.Permission      = permission;
                 hiveExperimentPermission.GrantedByUserId = grantedByUserId; // update grantedByUserId, always the last "granter" is stored
             }
         }
         else
         {
             // insert
             if (permission != Permission.NotAllowed)
             {
                 hiveExperimentPermission = new HiveExperimentPermission()
                 {
                     HiveExperimentId = hiveExperimentId, GrantedByUserId = grantedByUserId, GrantedUserId = grantedUserId, Permission = permission
                 };
                 db.HiveExperimentPermissions.InsertOnSubmit(hiveExperimentPermission);
             }
         }
         db.SubmitChanges();
     }
 }
Esempio n. 2
0
 public static void ToEntity(DT.HiveExperimentPermission source, HiveExperimentPermission target)
 {
     if ((source != null) && (target != null))
     {
         target.HiveExperimentId = source.HiveExperimentId; target.GrantedUserId = source.GrantedUserId; target.GrantedByUserId = source.GrantedByUserId; target.Permission = source.Permission;
     }
 }
Esempio n. 3
0
        public static HiveExperimentPermission ToEntity(DT.HiveExperimentPermission source)
        {
            if (source == null)
            {
                return(null);
            }
            var entity = new HiveExperimentPermission(); ToEntity(source, entity);

            return(entity);
        }
Esempio n. 4
0
 public static DT.HiveExperimentPermission ToDto(HiveExperimentPermission source)
 {
     if (source == null)
     {
         return(null);
     }
     return(new DT.HiveExperimentPermission {
         HiveExperimentId = source.HiveExperimentId, GrantedUserId = source.GrantedUserId, GrantedByUserId = source.GrantedByUserId, Permission = source.Permission
     });
 }
Esempio n. 5
0
 public Permission GetPermissionForExperiment(Guid experimentId, Guid userId)
 {
     using (var db = CreateContext()) {
         HiveExperiment hiveExperiment = db.HiveExperiments.SingleOrDefault(x => x.HiveExperimentId == experimentId);
         if (hiveExperiment == null)
         {
             return(Permission.NotAllowed);
         }
         if (hiveExperiment.OwnerUserId == userId)
         {
             return(Permission.Full);
         }
         HiveExperimentPermission permission = db.HiveExperimentPermissions.SingleOrDefault(p => p.HiveExperimentId == experimentId && p.GrantedUserId == userId);
         return(permission != null ? permission.Permission : Permission.NotAllowed);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Sets the permissions for a experiment. makes sure that only one permission per user exists.
 /// </summary>
 public void SetHiveExperimentPermission(Guid hiveExperimentId, Guid grantedByUserId, Guid grantedUserId, Permission permission) {
   using (var db = CreateContext()) {
     HiveExperimentPermission hiveExperimentPermission = db.HiveExperimentPermissions.SingleOrDefault(x => x.HiveExperimentId == hiveExperimentId && x.GrantedUserId == grantedUserId);
     if (hiveExperimentPermission != null) {
       if (permission == Permission.NotAllowed) {
         // not allowed, delete
         db.HiveExperimentPermissions.DeleteOnSubmit(hiveExperimentPermission);
       } else {
         // update
         hiveExperimentPermission.Permission = permission;
         hiveExperimentPermission.GrantedByUserId = grantedByUserId; // update grantedByUserId, always the last "granter" is stored
       }
     } else {
       // insert
       if (permission != Permission.NotAllowed) {
         hiveExperimentPermission = new HiveExperimentPermission() { HiveExperimentId = hiveExperimentId, GrantedByUserId = grantedByUserId, GrantedUserId = grantedUserId, Permission = permission };
         db.HiveExperimentPermissions.InsertOnSubmit(hiveExperimentPermission);
       }
     }
     db.SubmitChanges();
   }
 }
Esempio n. 7
0
 public static void ToEntity(DT.HiveExperimentPermission source, HiveExperimentPermission target) {
   if ((source != null) && (target != null)) {
     target.HiveExperimentId = source.HiveExperimentId; target.GrantedUserId = source.GrantedUserId; target.GrantedByUserId = source.GrantedByUserId; target.Permission = source.Permission;
   }
 }
Esempio n. 8
0
 public static HiveExperimentPermission ToEntity(DT.HiveExperimentPermission source) {
   if (source == null) return null;
   var entity = new HiveExperimentPermission(); ToEntity(source, entity);
   return entity;
 }
Esempio n. 9
0
 public static DT.HiveExperimentPermission ToDto(HiveExperimentPermission source) {
   if (source == null) return null;
   return new DT.HiveExperimentPermission { HiveExperimentId = source.HiveExperimentId, GrantedUserId = source.GrantedUserId, GrantedByUserId = source.GrantedByUserId, Permission = source.Permission };
 }