Пример #1
0
 public bool IsPermission(string roleFunctionName)
 {
     if (_PermissionService == null || string.IsNullOrWhiteSpace(roleFunctionName))
     {
         return(false);
     }
     return((from r in _PermissionService.ReadClientPermission(AppConfig.Instance.ClientID)
             where RoleIDs.Contains(r.RoleID) && r.RoleFunctionName == roleFunctionName
             select r).Count() > 0);
 }
Пример #2
0
        public bool IsAuthorize(string action, string controller, string method)
        {
            if (Username.Contains("0000"))
            {
                return(true);
            }
            var roleFunctionResult = from r in _PermissionService.ReadClientPermission(AppConfig.Instance.ClientID)
                                     where RoleIDs.Contains(r.RoleID) && r.APIAction == action && r.APIController == controller && r.APIMethod == method
                                     select r;

            return(roleFunctionResult.Any());
        }
        public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
        {
            var roles = new List <ulong>();

            foreach (var role in from r in context.Guild.Roles
                     where RoleIDs.Contains(r.Id) || RoleNames.Contains(r.Name)
                     select r)
            {
                roles.Add(role.Id);
            }

            return((context.User as IGuildUser).RoleIds.Intersect(roles).Any() ?
                   Task.FromResult(PreconditionResult.FromSuccess()) :
                   Task.FromResult(PreconditionResult.FromError($"User does not have required role!")));
        }