/// <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(); } }
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; } }
public static HiveExperimentPermission ToEntity(DT.HiveExperimentPermission source) { if (source == null) { return(null); } var entity = new HiveExperimentPermission(); ToEntity(source, entity); return(entity); }
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 }); }
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); } }
public static HiveExperimentPermission ToEntity(DT.HiveExperimentPermission source) { if (source == null) return null; var entity = new HiveExperimentPermission(); ToEntity(source, entity); return entity; }
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 }; }