コード例 #1
0
        public string Save(int[] sel, int UserID)
        {
            string status = "Error";

            try
            {
                if (UserID > 0)
                {
                    List <AssignedPermission> asigned = db.AssignedPermissions.Where(x => x.UserId == UserID).ToList();
                    db.AssignedPermissions.RemoveRange(asigned);

                    List <AssignedPermission> NewPermissions = new List <AssignedPermission>();
                    foreach (int i in sel)
                    {
                        AssignedPermission a = new AssignedPermission();
                        a.CreatedBy    = ActiveUserId;
                        a.CreatedOn    = DateTime.Now;
                        a.PermissionId = i;
                        a.UserId       = UserID;
                        a.UID          = Guid.NewGuid();
                        NewPermissions.Add(a);
                    }
                    db.AssignedPermissions.AddRange(NewPermissions);
                    if (db.SaveChanges() > 0)
                    {
                        status = "Success";
                    }
                }
            }
            catch (Exception ex)
            {
                ApplicationExceptionLogging(ex.ToString(), ex.StackTrace, "UserRightsController", "Save");
            }
            return(status);
        }
コード例 #2
0
        private void AddUserPermission(object sender)
        {
            PermissionAssignmentType permissionType = (PermissionAssignmentType)((ToolStripMenuItem)sender).Tag;
            PermissionView           p = (PermissionView)((KeyValuePair <string, PermissionView>)userPermissionTree.SelectedNode.Tag).Value;

            userPermissionTree.BeginUpdate();
            bool allow;

            if (permissionType == PermissionAssignmentType.AllowFromUser)
            {
                allow = true;
            }
            else
            {
                allow = false;
            }
            BubbleDownUserPermission(p, allow, PermissionFrom.User);

            userPermissionTree.EndUpdate();
            userPermissionTree.Refresh();
            if (_selectedAccount != null && _selectedUser != null)
            {
                if (!_selectedUser.AssignedPermissions.ContainsKey(_selectedAccount.ID.Value))
                {
                    _selectedUser.AssignedPermissions.Add(_selectedAccount.ID.Value, new List <AssignedPermission>());
                }

                AssignedPermission current = null;

                foreach (var assignedPermission in _selectedUser.AssignedPermissions[_selectedAccount.ID.Value])
                {
                    if (assignedPermission.PermissionType == p.Path)
                    {
                        current = assignedPermission;
                        break;
                    }
                }
                if (current == null)
                {
                    current = new AssignedPermission()
                    {
                        PermissionName = p.Name, PermissionType = p.Path, Value = allow
                    };
                    _selectedUser.AssignedPermissions[_selectedAccount.ID.Value].Add(current);
                }
                else
                {
                    current.Value = allow;
                }
            }
        }
コード例 #3
0
        private void BindExistingPermissions(List <IAction> allActions, List <IAction> userActions)
        {
            List <AssignedPermission> assignedPermissions = new List <AssignedPermission>();

            foreach (umbraco.interfaces.IAction a in allActions)
            {
                AssignedPermission p = new AssignedPermission();
                p.Permission    = a;
                p.HasPermission = (userActions != null ? userActions.Contains(a) : false);
                assignedPermissions.Add(p);
            }

            rptPermissionsList.DataSource = assignedPermissions;
            rptPermissionsList.DataBind();
        }
コード例 #4
0
ファイル: RoleAppService.cs プロジェクト: periface/SapTam
        private void AddPermission(ICollection <AssignedPermission> permissionsFound, ICollection <RolePermissionSetting> rolePermissions, Permission allPermission, bool granted)
        {
            var childPermissions = new List <AssignedPermission>();
            var permission       = new AssignedPermission()
            {
                DisplayName = allPermission.DisplayName.Localize(new LocalizationContext(LocalizationManager)),
                Granted     = granted,
                Name        = allPermission.Name,
            };

            if (allPermission.Children.Any())
            {
                foreach (var childPermission in allPermission.Children.WhereIf(AbpSession.TenantId.HasValue, a => a.Name != PermissionNames.PagesTenants))
                {
                    AddPermission(childPermissions, rolePermissions, childPermission, rolePermissions.Any(a => a.Name == childPermission.Name));
                }

                permission.ChildPermissions.AddRange(childPermissions);
            }

            permissionsFound.Add(permission);
        }
コード例 #5
0
 private void BindExistingPermissions(List<IAction> allActions, List<IAction> userActions)
 {
     
     List<AssignedPermission> assignedPermissions = new List<AssignedPermission>();
     foreach (umbraco.interfaces.IAction a in allActions)
     {
         AssignedPermission p = new AssignedPermission();
         p.Permission = a;
         p.HasPermission = (userActions != null ? userActions.Contains(a) : false);
         assignedPermissions.Add(p);
     }
     
     rptPermissionsList.DataSource = assignedPermissions;
     rptPermissionsList.DataBind();
     
 }