/// <summary> /// 获取权限访问对象 /// </summary> /// <param name="groupID">当前登录用户所属的组的主键</param> /// <returns>返回权限对象实例</returns> public PermissionEntry GetPermissionEntry(int groupID) { PermissionBuilder permissionBuilder = new DefaultPermissionBuilder(); PermissionEntry permissionEntry = permissionBuilder.ResolvePermission(groupID); return(permissionEntry); }
/// <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); }
/// <summary> /// Takes away a user's permission in a particular guild /// </summary> /// <param name="user">The user to take a permission from</param> /// <param name="guild">The guild to take their permission from in</param> /// <param name="permission">The permission to take</param> /// <returns>The permission that was taken (or null if it didn't exist)</returns> public async Task <PermissionEntry> RevokeUserPermission(IUser user, IGuild guild, string permission) { PermissionEntry entity = await _dbContext.Permissions.FirstOrDefaultAsync(x => x.ForeignId == user.Id && x.ServerId == guild.Id && x.Permission == permission); _dbContext.Permissions.Remove(entity); await _dbContext.SaveChangesAsync(); return(entity); }
/* ARGS: Input, string that contains the file name * RETURNS: NONE * Writes input to the database */ public static void permWrite(string input) { using (var db = new PermissionContext()) { Console.WriteLine($"Input{input}"); var entry = new PermissionEntry { Id = input }; var req = db.perms.Find(input); if (req != null) { return; } db.perms.Add(entry); db.SaveChanges(); } }
/// <summary> /// There are no comments for PermissionEntrySet in the schema. /// </summary> public void AddToPermissionEntrySet(PermissionEntry permissionEntry) { base.AddObject("PermissionEntrySet", permissionEntry); }
/// <summary> /// Create a new PermissionEntry object. /// </summary> /// <param name="groupID">Initial value of GroupID.</param> /// <param name="entityID">Initial value of EntityID.</param> /// <param name="permission">Initial value of Permission.</param> /// <param name="isDeny">Initial value of IsDeny.</param> /// <param name="doesApplyToTarget">Initial value of DoesApplyToTarget.</param> /// <param name="doesApplyToCollections">Initial value of DoesApplyToCollections.</param> /// <param name="doesApplyToAssets">Initial value of DoesApplyToAssets.</param> public static PermissionEntry CreatePermissionEntry(int groupID, int entityID, int permission, bool isDeny, bool doesApplyToTarget, bool doesApplyToCollections, bool doesApplyToAssets) { PermissionEntry permissionEntry = new PermissionEntry(); permissionEntry.GroupID = groupID; permissionEntry.EntityID = entityID; permissionEntry.Permission = permission; permissionEntry.IsDeny = isDeny; permissionEntry.DoesApplyToTarget = doesApplyToTarget; permissionEntry.DoesApplyToCollections = doesApplyToCollections; permissionEntry.DoesApplyToAssets = doesApplyToAssets; return permissionEntry; }