Exemple #1
0
        public List <PermissionItem> GetPermissionItems(Role role)
        {
            Permission <TA1, TA2> permission = Permissions.AlwaysGetPermission(role.RoleID);

            List <PermissionItem> items = new List <PermissionItem>();

            int index = 0;

            foreach (FieldInfo fieldInfo in GetFieldInfos())
            {
                PermissionItem item = new PermissionItem();

                item.FieldName = fieldInfo.Name;

                if (fieldInfo.IsDefined(typeof(PermissionItemAttribute), false))
                {
                    PermissionItemAttribute permissionItemAttribute = (PermissionItemAttribute)fieldInfo.GetCustomAttributes(typeof(PermissionItemAttribute), false)[0];

                    item.Name = permissionItemAttribute.Name;
                }

                if (string.IsNullOrEmpty(item.Name))
                {
                    item.Name = fieldInfo.Name;
                }

                item.Role      = role;
                item.InputName = "TA1_" + fieldInfo.Name + "_" + role.RoleID.ToString("N");

                // TA1 action = (TA1)Enum.Parse(typeof(TA1), fieldInfo.Name);

                if (permission.IsDenyTA1(index))
                {
                    item.IsDeny = true;
                }
                else if (permission.IsAllowTA1(index))
                {
                    item.IsAllow = true;
                }
                else
                {
                    item.IsNotset = true;
                }

                item.IsDisabled = permission.IsDisabledTA1(index);

                items.Add(item);

                index++;
            }

            return(items);
        }
Exemple #2
0
        public Dictionary <string, PermissionItem> GetPermissionItemWithTargetTable(Role role)
        {
            Permission <TA1, TA2> permission = Permissions.AlwaysGetPermission(role.RoleID);

            Dictionary <string, PermissionItem> items = new Dictionary <string, PermissionItem>(StringComparer.OrdinalIgnoreCase);

            int index = 0;

            foreach (FieldInfo fieldInfo in GetFieldInfosWithTarget())
            {
                PermissionItem item = new PermissionItem();

                item.FieldName = fieldInfo.Name;

                if (fieldInfo.IsDefined(typeof(PermissionItemAttribute), false))
                {
                    PermissionItemAttribute permissionItemAttribute = (PermissionItemAttribute)fieldInfo.GetCustomAttributes(typeof(PermissionItemAttribute), false)[0];

                    item.Name = permissionItemAttribute.Name;
                }

                if (string.IsNullOrEmpty(item.Name))
                {
                    item.Name = fieldInfo.Name;
                }

                item.Role      = role;
                item.InputName = "TA2_" + fieldInfo.Name + "_" + role.RoleID.ToString("N");

                // TA1 action = (TA1)Enum.Parse(typeof(TA1), fieldInfo.Name);

                if (permission.IsDenyTA2(index))
                {
                    item.IsDeny = true;
                }
                else if (permission.IsAllowTA2(index))
                {
                    item.IsAllow = true;
                }
                else
                {
                    item.IsNotset = true;
                }

                item.IsDisabled = permission.IsDisabledTA2(index);


                string fileName = null;
                if (fieldInfo.IsDefined(typeof(BackendPageAttribute), false))
                {
                    BackendPageAttribute backendPageAttribute = (BackendPageAttribute)fieldInfo.GetCustomAttributes(typeof(BackendPageAttribute), false)[0];

                    fileName = backendPageAttribute.FileName;
                }

                if (fileName != null)
                {
                    items.Add(fileName, item);
                }

                index++;
            }

            return(items);
        }
Exemple #3
0
        public void GetPermissionItemAttributeSet(Guid roleID, FieldInfo actionField, out bool isAllow, out bool isDeny, out bool editable)
        {
            isAllow  = false;
            isDeny   = false;
            editable = false;

            PermissionItemAttribute permissionItemAttribute = (PermissionItemAttribute)actionField.GetCustomAttributes(typeof(PermissionItemAttribute), false)[0];

            RoleOption roleOption;

            if (roleID == Role.Everyone.RoleID)
            {
                roleOption = permissionItemAttribute.Everyone;
            }

            else if (roleID == Role.Guests.RoleID)
            {
                roleOption = permissionItemAttribute.Guests;
            }

            else if (roleID == Role.Users.RoleID)
            {
                roleOption = permissionItemAttribute.Users;
            }

            else if (roleID == Role.NewUsers.RoleID)
            {
                roleOption = permissionItemAttribute.NewUsers;
            }

            else if (roleID == Role.RealnameNotProvedUsers.RoleID)
            {
                roleOption = permissionItemAttribute.RealnameNotProvedUsers;
            }

            else if (roleID == Role.EmailNotProvedUsers.RoleID)
            {
                roleOption = permissionItemAttribute.EmailNotProvedUsers;
            }

            else if (roleID == Role.Moderators.RoleID)
            {
                roleOption = permissionItemAttribute.Moderators;
            }

            else if (roleID == Role.CategoryModerators.RoleID)
            {
                roleOption = permissionItemAttribute.CategoryModerators;
            }

            else if (roleID == Role.SuperModerators.RoleID)
            {
                roleOption = permissionItemAttribute.SuperModerators;
            }

            else if (roleID == Role.Administrators.RoleID)
            {
                roleOption = permissionItemAttribute.Administrators;
            }

            else if (roleID == Role.Owners.RoleID)
            {
                roleOption = permissionItemAttribute.Owners;
            }

            else if (roleID == Role.ForumBannedUsers.RoleID)
            {
                roleOption = permissionItemAttribute.ForumBannedUsers;
            }

            else if (roleID == Role.FullSiteBannedUsers.RoleID)
            {
                roleOption = permissionItemAttribute.FullSiteBannedUsers;
            }

            else
            {
                roleOption = RoleOption.DefaultNotset;
            }

            switch (roleOption)
            {
            case RoleOption.AlwaysAllow:
                isAllow  = true;
                editable = false;
                break;

            case RoleOption.AlwaysDeny:
                isDeny   = true;
                editable = false;
                break;

            case RoleOption.AlwaysNotset:
                editable = false;
                break;

            case RoleOption.DefaultAllow:
                isAllow  = true;
                editable = true;
                break;

            case RoleOption.DefaultDeny:
                isDeny   = true;
                editable = true;
                break;

            case RoleOption.DefaultNotset:
                editable = true;
                break;
            }
        }