public async Task SetupDefaultPermissions()
        {
            if (await _permissionsService.ContainsDefaultPermissionsAsync())
            {
                return;
            }

            var memberGroups = _intranetMemberGroupService.GetAll();

            var permissionsList = memberGroups
                                  .Where(n => n.Name == MemberGroups.GroupWebMaster ||
                                         n.Name == MemberGroups.GroupUiUser ||
                                         n.Name == MemberGroups.GroupUiPublisher)
                                  .SelectMany(member =>
            {
                switch (member.Name)
                {
                case MemberGroups.GroupWebMaster:
                    return(SetupWebMasterMemberGroup(member));

                case MemberGroups.GroupUiPublisher:
                    return(SetupUiPublisherMemberGroup(member));

                default:
                    return(SetupUiUserMemberGroup(member));
                }
            })
                                  .ToArray();

            await _permissionsService.SaveAsync(permissionsList);
        }
Exemple #2
0
        public ExecutionResult Execute()
        {
            var memberGroups = _intranetMemberGroupService.GetAll();

            var permissions = memberGroups.Choose(group =>
            {
                switch (group.Name)
                {
                case MemberGroups.GroupWebMaster:
                    return(Some(SetupWebMasterMemberGroup(group)));

                case MemberGroups.GroupUiPublisher:
                    return(Some(SetupUiPublisherMemberGroup(group)));

                case MemberGroups.GroupUiUser:
                    return(Some(SetupUiUserMemberGroup(group)));

                default:
                    return(None);
                }
            }).SelectMany(identity);

            _permissionsService.Save(permissions);
            return(ExecutionResult.Success);
        }
        public ExecutionResult Execute()
        {
            _logger.Info <SetupDefaultMemberGroupsPermissionsStep>("SetupDefaultMemberGroupsStep is running");
            var memberGroups = _intranetMemberGroupService.GetAll();

            if (!memberGroups.Any(mg => mg.Name == "UiUser"))
            {
                _intranetMemberGroupService.Create("UiUser");
                _logger.Info <SetupDefaultMemberGroupsPermissionsStep>("UI User role has been created");
            }

            if (!memberGroups.Any(mg => mg.Name == "UiPublisher"))
            {
                _intranetMemberGroupService.Create("UiPublisher");
                _logger.Info <SetupDefaultMemberGroupsPermissionsStep>("UI Publisher role has been created");
            }

            if (!memberGroups.Any(mg => mg.Name == "WebMaster"))
            {
                _intranetMemberGroupService.Create("WebMaster");
                _logger.Info <SetupDefaultMemberGroupsPermissionsStep>("Web Master role has been created");
            }

            MemoryCache.Default.Trim(100);

            return(ExecutionResult.Success);
        }
Exemple #4
0
        public ExecutionResult Execute()
        {
            _logger.Info <SetupDefaultMemberGroupsPermissionsStep>("SetupDefaultMemberGroupsPermissionsStep is running");
            var existedPermissions = _permissionsService.GetAll();

            if (existedPermissions.Any())
            {
                _logger.Info <SetupDefaultMemberGroupsPermissionsStep>("Database contains some permissions. Step has been skipped");
                return(ExecutionResult.Success);
            }

            var memberGroups = _intranetMemberGroupService.GetAll();

            var permissions = memberGroups.Select(group =>
            {
                switch (group.Name)
                {
                case UsersInstallationConstants.MemberGroups.GroupWebMaster:
                    _logger.Info <SetupDefaultMemberGroupsPermissionsStep>("Setting permissions for Web Master...");
                    return(SetupWebMasterMemberGroup(group));

                case UsersInstallationConstants.MemberGroups.GroupUiPublisher:
                    _logger.Info <SetupDefaultMemberGroupsPermissionsStep>("Setting permissions for UI Publisher...");
                    return(SetupUiPublisherMemberGroup(group));

                case UsersInstallationConstants.MemberGroups.GroupUiUser:
                    _logger.Info <SetupDefaultMemberGroupsPermissionsStep>("Setting permissions for UI User...");
                    return(SetupUiUserMemberGroup(group));

                default:
                    return(null);
                }
            })
                              .WhereNotNull()
                              .SelectMany(p => p);

            _logger.Info <SetupDefaultMemberGroupsPermissionsStep>($"{permissions.Count()} permissions has been saved");
            _permissionsService.Save(permissions);
            MemoryCache.Default.Trim(100);
            return(ExecutionResult.Success);
        }