Beispiel #1
0
        /// <summary>
        /// Delete a link between a role and an extension.
        /// </summary>
        /// <param name="storage_">Storage interface provided by services container.</param>
        /// <param name="roleManager_">Roles manager instance.</param>
        /// <param name="extensionName_">Extension name.</param>
        /// <param name="roleName_">Role name.</param>
        /// <returns>Return true on success, false when forbidden, null when not found.</returns>
        internal static async Task <bool?> DeleteRoleExtensionLinkAsync(IStorage storage_, RoleManager <IdentityRole <string> > roleManager_, string extensionName_, string roleName_)
        {
            string roleId = (await roleManager_.FindByNameAsync(roleName_))?.Id;

            if (string.IsNullOrEmpty(roleId))
            {
                return(null);
            }

            IRolePermissionRepository repo = storage_.GetRepository <IRolePermissionRepository>();

            if (repo.FindBy(roleId, extensionName_) == null)
            {
                return(null);
            }

            if (extensionName_ == Constants.SoftinuxBaseSecurity)
            {
                if (await ReadGrants.IsRoleLastAdminPermissionLevelGrantForExtensionAsync(roleManager_, storage_, roleName_, extensionName_))
                {
                    return(false);
                }
            }

            repo.Delete(roleId, extensionName_);
            await storage_.SaveAsync();

            return(true);
        }
Beispiel #2
0
        public async Task <IActionResult> DeleteRoleExtensionLink(string roleName_, string scope_)
        {
            string roleId = (await _roleManager.FindByNameAsync(roleName_)).Id;
            IRolePermissionRepository repo = Storage.GetRepository <IRolePermissionRepository>();

            if (repo.FindBy(roleId, scope_) != null)
            {
                repo.Delete(roleId, scope_);
                Storage.Save();
                return(new JsonResult(true));
            }
            return(new JsonResult(false));
        }