Пример #1
0
        public void UpdateUser(UserWithPermissionsContract contract)
        {
            ParamIs.NotNull(() => contract);

            UpdateEntity <User>(contract.Id, (session, user) => {
                if (!EntryPermissionManager.CanEditUser(PermissionContext, user.GroupId))
                {
                    var loggedUser = GetLoggedUser(session);
                    var msg        = string.Format("{0} (level {1}) not allowed to edit {2}", loggedUser, loggedUser.GroupId, user);
                    log.Error(msg);
                    throw new NotAllowedException(msg);
                }

                if (EntryPermissionManager.CanEditGroupTo(PermissionContext, contract.GroupId))
                {
                    user.GroupId = contract.GroupId;
                }

                if (EntryPermissionManager.CanEditAdditionalPermissions(PermissionContext))
                {
                    user.AdditionalPermissions = new PermissionCollection(contract.AdditionalPermissions.Select(p => PermissionToken.GetById(p.Id)));
                }

                var diff = OwnedArtistForUser.Sync(user.AllOwnedArtists, contract.OwnedArtistEntries, a => user.AddOwnedArtist(session.Load <Artist>(a.Artist.Id)));
                SessionHelper.Sync(session, diff);

                user.Active = contract.Active;

                AuditLog(string.Format("updated {0}", EntryLinkFactory.CreateEntryLink(user)), session);
            }, PermissionToken.ManageUserPermissions, skipLog: true);
        }
Пример #2
0
        public UserEdit()
        {
            var groups = EnumVal <UserGroupId> .Values.Where(g => EntryPermissionManager.CanEditGroupTo(Login.Manager, g)).ToArray();

            EditableGroups = new TranslateableEnum <UserGroupId>(() => global::Resources.UserGroupNames.ResourceManager, groups);
            OwnedArtists   = new List <ArtistForUserContract>();
            Permissions    = new List <PermissionFlagEntry>();
        }
Пример #3
0
        public static TranslateableEnum <UserGroupId> GetEditableGroups(LoginManager manager)
        {
            var groups = EnumVal <UserGroupId> .Values.Where(g => EntryPermissionManager.CanEditGroupTo(manager, g)).ToArray();

            return(new TranslateableEnum <UserGroupId>(() => global::Resources.UserGroupNames.ResourceManager, groups));
        }