Exemplo n.º 1
0
        /// <summary>
        /// 迭代加载菜单导航
        /// </summary>
        /// <param name="oldlist">源数据</param>
        /// <param name="newlist">新数据</param>
        /// <param name="parentId"></param>
        private void GetChilds(List<Navigations.Navigation> oldlist, Permission permission, int parentId)
        {
            Func<Navigations.Navigation, bool> predicate = n => n.ParentId == parentId;
            if (parentId == 0)
            {
                predicate = n => n.ParentId == null || n.ParentId == parentId;
            }

            var subs = oldlist
            .Where(predicate)
            .OrderBy(n => n.SortId)
            .ToList();

            //循环
            foreach (var item in subs)
            {
                var subPermission = permission.CreateChildPermission(
                    item.PermissionName,
                    L(item.LocalizableString),
                    multiTenancySides: item.MultiTenancySide.HasValue
                    ? item.MultiTenancySide.Value
                    : (MultiTenancySides.Host | MultiTenancySides.Tenant));
                //迭代
                GetChilds(oldlist, subPermission, item.Id);
            }
        }
Exemplo n.º 2
0
 public Abp.Authorization.Permission EditPermission(string oldName, Abp.Authorization.Permission parent, string name, ILocalizableString displayName = null,
                                                    ILocalizableString description       = null,
                                                    MultiTenancySides multiTenancySides  = MultiTenancySides.Tenant | MultiTenancySides.Host,
                                                    IFeatureDependency featureDependency = null, Dictionary <string, object> properties = null)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 3
0
        private async Task <Abp.Authorization.Permission> _CreatePermissionAsync(PermissionDefinition permission)
        {
            Abp.Authorization.Permission newPermission = null;
            if (!string.IsNullOrEmpty(permission.Parent))
            {
                // add new permission to parent
                var parent = GetPermission(permission.Parent);
                if (parent != null)
                {
                    newPermission = parent.CreateChildPermission(permission.Name,
                                                                 (permission.DisplayName ?? "").L(),
                                                                 (permission.Description ?? "").L(),
                                                                 properties: new Dictionary <string, object>()
                    {
                        { "IsDbPermission", true }
                    }
                                                                 );
                }
            }
            else
            {
                newPermission = CreatePermission(
                    permission.Name,
                    (permission.DisplayName ?? "").L(),
                    (permission.Description ?? "").L(),
                    properties: new Dictionary <string, object>()
                {
                    { "IsDbPermission", true }
                });
            }

            return(newPermission);
        }
 /// <summary>
 /// 递归加载所有权限
 /// </summary>
 /// <param name="rootPermission"></param>
 /// <param name="permission"></param>
 private void AddPermissions(PermissionInfo rootPermission, Permission permission)
 {
     var permissions = PermissionInfos.Where(p => p.ParentName == rootPermission.Name);
     foreach (PermissionInfo permissionInfo in permissions)
     {
         var childernPermission = permission.CreateChildPermission(permissionInfo.Name,
               new FixedLocalizableString(permissionInfo.DisplayName), permissionInfo.IsGrantedByDefault);
         AddPermissions(permissionInfo, childernPermission);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Adds a child permission.
 /// A child permission can be granted only if parent is granted.
 /// </summary>
 /// <returns>Returns newly created child permission</returns>
 public Permission CreateChildPermission(
     string name,
     string displayName, 
     bool isGrantedByDefault = false, 
     IFeatureDependency featureDependency = null)
 {
     var permission = new Permission(name, displayName, isGrantedByDefault, featureDependency) { Parent = this };
     _children.Add(permission);
     return permission;
 }
        public Permission CreatePermission(string name, ILocalizableString displayName = null, bool isGrantedByDefault = false, ILocalizableString description = null, MultiTenancySides multiTenancySides = MultiTenancySides.Host | MultiTenancySides.Tenant)
        {
            if (Permissions.ContainsKey(name))
            {
                throw new AbpException("There is already a permission with name: " + name);
            }

            var permission = new Permission(name, displayName, isGrantedByDefault, description, multiTenancySides);
            Permissions[permission.Name] = permission;
            return permission;
        }
Exemplo n.º 7
0
        private void CreateChildPermi(Abp.Authorization.Permission permission, long id)
        {
            var childPermission = _permissions.Where(s => s.ParentId == id);

            if (childPermission.Count() > 0)
            {
                childPermission.ToList().ForEach(z =>
                {
                    var grandPermi = permission.CreateChildPermission(z.Name, L(z.DisplayName));
                    CreateChildPermi(grandPermi, z.Id);
                });
            }
        }
        public Permission CreatePermission(
          string name,
          string displayName,
          bool isGrantedByDefault = false,
         // ILocalizableString description = null,
          IFeatureDependency featureDependency = null)
        {
            if (Permissions.ContainsKey(name))
            {
                throw new AbpException("There is already a permission with name: " + name);
            }

            var permission = new Permission(name, displayName, isGrantedByDefault, featureDependency);
            Permissions[permission.Name] = permission;
            return permission;
        }
        public Permission CreatePermission(
            string name, 
            ILocalizableString displayName = null, 
            ILocalizableString description = null, 
            MultiTenancySides multiTenancySides = MultiTenancySides.Host | MultiTenancySides.Tenant,
            IFeatureDependency featureDependency = null)
        {
            if (Permissions.ContainsKey(name))
            {
                throw new AbpException("There is already a permission with name: " + name);
            }

            var permission = new Permission(name, displayName, description, multiTenancySides, featureDependency);
            Permissions[permission.Name] = permission;
            return permission;
        }
        /// <summary>
        /// 创建权限
        /// </summary>
        /// <param name="name">权限名称</param>
        /// <param name="displayName">权限显示名称</param>
        /// <param name="isGrantedByDefault"></param>
        /// <param name="description">权限描述</param>
        /// <param name="multiTenancySides">多租户</param>
        /// <param name="featureDependency">特征依赖</param>
        /// <returns></returns>
        public Permission CreatePermission(
            string name, 
            ILocalizableString displayName = null, 
            bool isGrantedByDefault = false, 
            ILocalizableString description = null, 
            MultiTenancySides multiTenancySides = MultiTenancySides.Host | MultiTenancySides.Tenant,
            IFeatureDependency featureDependency = null)
        {
            //权限字典中是否包含指定的键
            if (Permissions.ContainsKey(name))
            {
                //权限字典中已经包含这个权限,名称为:
                throw new AbpException("There is already a permission with name: " + name);
            }

            var permission = new Permission(name, displayName, isGrantedByDefault, description, multiTenancySides, featureDependency);
            Permissions[permission.Name] = permission;
            return permission;
        }
Exemplo n.º 11
0
        public async Task<GetRoleForEditOutput> GetRoleForEdit(NullableIdInput input)
        {
            var permissions = PermissionManager.GetAllPermissions();
            var grantedPermissions = new Permission[0];
            RoleEditDto roleEditDto;

            if (input.Id.HasValue) //Editing existing role?
            {
                var role = await _roleManager.GetRoleByIdAsync(input.Id.Value);
                grantedPermissions = (await _roleManager.GetGrantedPermissionsAsync(role)).ToArray();
                roleEditDto = role.MapTo<RoleEditDto>();
            }
            else
            {
                roleEditDto = new RoleEditDto();
            }

            return new GetRoleForEditOutput
                   {
                       Role = roleEditDto,
                       Permissions = permissions.MapTo<List<FlatPermissionDto>>().OrderBy(p => p.DisplayName).ToList(),
                       GrantedPermissionNames = grantedPermissions.Select(p => p.Name).ToList()
                   };
        }
Exemplo n.º 12
0
        private void CreateChildPermissions(List <PermissionDefinition> dbPermissions, Abp.Authorization.Permission permission)
        {
            var dbChildPermissions = dbPermissions.Where(x => x.Parent == permission.Name).ToList();

            foreach (var dbChildPermission in dbChildPermissions)
            {
                var childPermission =
                    permission.CreateChildPermission(dbChildPermission.Name, dbChildPermission.DisplayName.L(), dbChildPermission.Description.L());
                CreateChildPermissions(dbPermissions, childPermission);
                dbPermissions.Remove(dbChildPermission);
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Adds a child permission.
 /// A child permission can be granted only if parent is granted.
 /// </summary>
 /// <returns>Returns newly created child permission</returns>
 public Permission CreateChildPermission(
     string name, 
     ILocalizableString displayName = null, 
     bool isGrantedByDefault = false, 
     ILocalizableString description = null, 
     MultiTenancySides multiTenancySides = MultiTenancySides.Host | MultiTenancySides.Tenant,
     IFeatureDependency dependedFeature = null)
 {
     var permission = new Permission(name, displayName, isGrantedByDefault, description, multiTenancySides, dependedFeature) { Parent = this };
     _children.Add(permission);
     return permission;
 }
Exemplo n.º 14
0
 /// <summary>
 /// Adds a child permission.
 /// A child permission can be granted only if parent is granted.
 /// </summary>
 /// <returns>Returns newly created child permission</returns>
 public Permission CreateChildPermission(string name, ILocalizableString displayName, bool isGrantedByDefault = false, ILocalizableString description = null)
 {
     var permission = new Permission(name, displayName, isGrantedByDefault, description) { Parent = this };
     _children.Add(permission);
     return permission;
 }
Exemplo n.º 15
0
 /// <summary>
 /// Check whether a user is granted for a permission.
 /// </summary>
 /// <param name="user">User</param>
 /// <param name="permission">Permission</param>
 public virtual async Task<bool> IsGrantedAsync(AuthorityUserInfo user, Permission permission)
 {
    
     return false;
 }
Exemplo n.º 16
0
        private async Task CreateChildPermissionsAsync(List <PermissionDefinition> dbPermissions, Abp.Authorization.Permission permission)
        {
            var dbChildPermissions = dbPermissions.Where(x => x.Parent == permission.Name).ToList();

            foreach (var dbChildPermission in dbChildPermissions)
            {
                var childPermission = await _permissionManager.CreatePermissionAsync(dbChildPermission);
                await CreateChildPermissionsAsync(dbPermissions, childPermission);

                dbPermissions.Remove(dbChildPermission);
            }
        }
 /// <summary>
 /// Creates a new permission under this group.
 /// </summary>
 /// <param name="name">Unique name of the permission</param>
 /// <param name="displayName">Display name of the permission</param>
 /// <param name="isGrantedByDefault">Is this permission granted by default. Default value: false.</param>
 /// <param name="description">A brief description for this permission</param>
 /// <returns>New created permission</returns>
 public Permission CreatePermission(string name, ILocalizableString displayName, bool isGrantedByDefault = false, ILocalizableString description = null)
 {
     var permission = new Permission(name, displayName, isGrantedByDefault, description);
     _permissions.Add(permission);
     return permission;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Adds a child permission.
 /// A child permission can be granted only if parent is granted.
 /// </summary>
 /// <returns>Returns newly created child permission</returns>
 public Permission CreateChildPermission(
     string name, 
     ILocalizableString displayName = null, 
     ILocalizableString description = null, 
     MultiTenancySides multiTenancySides = MultiTenancySides.Host | MultiTenancySides.Tenant,
     IFeatureDependency featureDependency = null)
 {
     var permission = new Permission(name, displayName, description, multiTenancySides, featureDependency) { Parent = this };
     _children.Add(permission);
     return permission;
 }
Exemplo n.º 19
0
        // permissions
        public override Task <bool> IsGrantedAsync(User user, Abp.Authorization.Permission permission)
        {
            var fdc = FeatureDependencyContext;

            return(base.IsGrantedAsync(user, permission));
        }