Exemplo n.º 1
0
        public void LoadPermissions(Assembly assembly)
        {
            var permissions = assembly.GetTypes()
                              .SelectMany(x => x.GetMethods())
                              .Where(x => x.GetCustomAttributes <Preconditions.RequireCustomPermissionAttribute>().Count() > 0)
                              .Select(x => x.GetCustomAttribute <Preconditions.RequireCustomPermissionAttribute>().Permission);

            foreach (var p in permissions)
            {
                if (!AllPermissions.Contains(p))
                {
                    AllPermissions.Add(p);
                }
            }
        }
Exemplo n.º 2
0
        public Result AddPermission(SocketRole role, string perm)
        {
            // Add wildcard permission
            if (perm.Contains("*"))
            {
                return(AddWildcardPermission(role, perm));
            }

            // Add specific permission
            if (!AllPermissions.Contains(perm))
            {
                return new Result {
                           Type = ResultType.Fail, Message = "Permission not found or invalid format."
                }
            }
            ;
            if (!Permissions.ContainsKey(role.Id))
            {
                var permissions = new HashSet <string>();

                permissions.Add(perm);
                Permissions.Add(role.Id, permissions);
                return(new Result {
                    Type = ResultType.Success, Message = "Created permissions set for role and added specified permission."
                });
            }
            if (!Permissions[role.Id].Add(perm))
            {
                return new Result {
                           Type = ResultType.Warning, Message = "Role already has permission."
                }
            }
            ;

            return(new Result {
                Type = ResultType.Success, Message = "Added specified permission."
            });
        }
Exemplo n.º 3
0
 public bool IsForumReadOnly(int forumId)
 => IsAnonymous || AllPermissions?.Contains(new Permissions {
     ForumId = forumId, AuthRoleId = Constants.FORUM_READONLY_ROLE
 }) == true;
Exemplo n.º 4
0
 public bool IsForumRestricted(int forumId)
 => AllPermissions?.Contains(new Permissions {
     ForumId = forumId, AuthRoleId = Constants.FORUM_RESTRICTED_ROLE
 }) == true;