/// <summary> /// Creates a new permission and adds it to the database. /// </summary> /// <param name="g">The group to give permission to.</param> /// <param name="ent">The entity on which the permissio act.</param> /// <param name="perm">The permission to give to the group.</param> /// <param name="deny">Whether or not to explicitly deny this permission.</param> /// <param name="applytarget">Whether or not the permission applies to this entity (versus its contents).</param> /// <param name="applycolls">Whether or not the permission applies to collections within this entity.</param> /// <param name="applyassets">Whether or not the permission applies to assets within this entity.</param> /// <returns>The new permission entry or null.</returns> /// <exception cref="NoPolicyException">If the current user does not have the ability to create a new permission.</exception> public static PermissionEntry CreatePermissionEntry(Group g, PermissionableEntity ent, Permission perm, bool deny, bool applytarget, bool applycolls, bool applyassets) { if (!DoesUserHavePerm(WindchimeSession.Current.User, ent, Permission.EditPermissions)) { throw new NoPermissionException(Permission.EditPermissions); } if (g == null || ent == null) { return(null); } PermissionEntry pent = new PermissionEntry(); pent.GroupID = g.GroupID; pent.EntityID = ent.EntityID; pent.Permission = (int)perm; pent.IsDeny = deny; pent.DoesApplyToTarget = applytarget; pent.DoesApplyToCollections = applycolls; pent.DoesApplyToAssets = applyassets; using (WindchimeEntities wce = new WindchimeEntities()) { wce.AddToPermissionEntrySet(pent); wce.SaveChanges(); wce.Detach(pent); } return(pent); }
public static void DeletePermissionEntry(Group g, PermissionableEntity ent, Permission perm) { if (!DoesUserHavePerm(WindchimeSession.Current.User, ent, Permission.EditPermissions)) { throw new NoPermissionException(Permission.EditPermissions); } if (g == null || ent == null) { return; } using (WindchimeEntities wce = new WindchimeEntities()) { var deletePerm = (from PermissionEntry pe in wce.PermissionEntrySet where pe.GroupID == g.GroupID && pe.EntityID == ent.EntityID && pe.Permission == (int)perm select pe); foreach (var pe in deletePerm) { wce.DeleteObject(pe); } } }
/// <summary> /// There are no comments for PermissionableEntities in the schema. /// </summary> public void AddToPermissionableEntities(PermissionableEntity permissionableEntity) { base.AddObject("PermissionableEntities", permissionableEntity); }
/// <summary> /// Create a new PermissionableEntity object. /// </summary> /// <param name="entityID">Initial value of EntityID.</param> /// <param name="published">Initial value of Published.</param> public static PermissionableEntity CreatePermissionableEntity(int entityID, bool published) { PermissionableEntity permissionableEntity = new PermissionableEntity(); permissionableEntity.EntityID = entityID; permissionableEntity.Published = published; return permissionableEntity; }
public static bool DoesUserHavePerm(User u, PermissionableEntity ent, Permission perm) { return(true); }
public static bool DoesGroupHavePerm(Group g, PermissionableEntity ent, Permission perm) { return(true); }