Пример #1
0
 public RocketPermissionsGroup GetGroup(string groupId)
 {
     return(AsyncHelper.RunSync(async() =>
     {
         var group = await m_PermissionRoleStore.GetRoleAsync(groupId);
         return new RocketPermissionsGroup(group.Id, group.DisplayName, null, new List <string>(), new List <Permission>());
     }));
 }
Пример #2
0
        protected override async Task OnExecuteAsync()
        {
            if (Context.Parameters.Length != 3)
            {
                throw new CommandWrongUsageException(Context);
            }

            IPermissionActor target;
            string           permission;

            var actorType          = Context.Parameters[0].ToLower();
            var targetName         = Context.Parameters[1];
            var permissionToUpdate = Context.Parameters[2];

            switch (actorType)
            {
            case "r":
            case "role":
                permission = "Manage.Roles." + targetName;
                target     = await m_PermissionRoleStore.GetRoleAsync(targetName);

                if (target == null)
                {
                    await Context.Actor.PrintMessageAsync($"Role \"{targetName}\" was not found.", Color.Red);

                    return;
                }

                break;

            case "p":
            case "player":
                permission = "Manage.Players";
                var id = await Context.Parameters.GetAsync <string>(1);

                var user = await m_UserDataStore.GetUserDataAsync(id, actorType);

                if (user == null)
                {
                    // todo: localizable
                    throw new UserFriendlyException($"User not found: {id}");
                }

                target = (UserDataPermissionActor)user;
                break;

            default:
                throw new CommandWrongUsageException(Context);
            }

            if (await CheckPermissionAsync(permission) != PermissionGrantResult.Grant)
            {
                throw new NotEnoughPermissionException(Context, permission);
            }

            await ExecuteUpdateAsync(target, permissionToUpdate);
        }
Пример #3
0
        public async Task <IPermissionRole> GetRoleAsync(string id)
        {
            if (IsRocketModRole(id))
            {
                throw new System.NotImplementedException();
            }

            return(await m_BasePermissionRoleStore.GetRoleAsync(id));
        }
Пример #4
0
        protected override async Task ExecuteUpdateAsync(IPermissionActor target, string roleId)
        {
            var role = await m_PermissionRoleStore.GetRoleAsync(roleId);

            if (role == null)
            {
                throw new UserFriendlyException($"Permission role not found: {roleId}");
            }

            await ExecuteUpdateAsync(target, role);
        }
        public async Task <IPermissionRole?> GetRoleAsync(string roleId)
        {
            if (string.IsNullOrEmpty(roleId))
            {
                throw new ArgumentException(nameof(roleId));
            }

            if (RocketModIntegrationEnabled() && IsRocketModRole(roleId))
            {
                return(new RocketGroupWrapper(R.Permissions.GetGroup(roleId)));
            }

            return(await m_BasePermissionRoleStore.GetRoleAsync(roleId));
        }
Пример #6
0
        public RocketPermissionsGroup?GetGroup(string groupId)
        {
            if (string.IsNullOrEmpty(groupId))
            {
                throw new ArgumentException(nameof(groupId));
            }

            return(AsyncHelper.RunSync(async() =>
            {
                var group = await m_PermissionRoleStore.GetRoleAsync(groupId);
                if (@group == null)
                {
                    return null;
                }

                return new RocketPermissionsGroup(group.Id, group.DisplayName, null, new List <string>(), new List <Permission>());
            }));
        }
Пример #7
0
        protected override async Task OnExecuteAsync()
        {
            if (Context.Parameters.Length != 3)
            {
                throw new CommandWrongUsageException(Context);
            }

            IPermissionActor target;

            var actorType          = Context.Parameters[0].ToLower();
            var permission         = "permissions.manage." + actorType;
            var targetName         = Context.Parameters[1];
            var permissionToUpdate = Context.Parameters[2];

            switch (actorType)
            {
            case "r":
            case "role":
                permission = "permissions.manage.roles." + targetName;
                target     = await m_PermissionRoleStore.GetRoleAsync(targetName);

                // todo: register on startup instead of here so it can get written to a help file
                m_PermissionRegistry.RegisterPermission(Context.CommandRegistration.Component, permission, description: $"Manage role: {targetName}");

                if (target == null)
                {
                    await Context.Actor.PrintMessageAsync($"Role \"{targetName}\" was not found.", Color.Red);

                    return;
                }

                break;

            case "p":
            case "player":
                permission = "permissions.manage.players";
                actorType  = KnownActorTypes.Player;
                goto default;

            default:
                var idOrName = await Context.Parameters.GetAsync <string>(1);

                var user = await m_UserManager.FindUserAsync(actorType, idOrName, UserSearchMode.NameOrId);

                m_PermissionRegistry.RegisterPermission(Context.CommandRegistration.Component, permission, description: $"Manage actor: {actorType}");

                if (user == null)
                {
                    // todo: make localizable
                    throw new UserFriendlyException($"Player not found: {idOrName}");
                }

                var userData = await m_UserDataStore.GetUserDataAsync(user.Id, actorType);

                target = (UserDataPermissionActor)userData;
                break;
            }

            // we call m_PermissionChecker from here so the permission will become OpenMod.Core.manage.players instead of
            if (await m_PermissionChecker.CheckPermissionAsync(Context.Actor, permission) != PermissionGrantResult.Grant)
            {
                throw new NotEnoughPermissionException(Context, permission);
            }

            await ExecuteUpdateAsync(target, permissionToUpdate);
        }