Esempio n. 1
0
        public async Task <bool> RoleAssignmentExistsAsync(AssignRoleToUser model)
        {
            var userRoles = await _roleAssignmentRepository.GetRoleAssignmentsByUserAsync(model.UserId);

            var oldRoleAssignments = _mapper.Map <List <UserRoles>, List <RoleView> >(userRoles);

            var filteredRoleAssignments = oldRoleAssignments
                                          .Where(role => role.RoleType.Equals(model.RoleType, StringComparison.OrdinalIgnoreCase));

            return((from roleAssignment in filteredRoleAssignments
                    let modelDataScopeDictionary = model.DataScope as IDictionary <string, JToken>
                                                   let roleDataScopeDictionary = roleAssignment.DataScope as IDictionary <string, JToken>
                                                                                 select AreRoleAssignmentsEqual(modelDataScopeDictionary, roleDataScopeDictionary)).FirstOrDefault());
        }
Esempio n. 2
0
        public async Task <List <ConfigurationView> > GetAssignableRoleConfigurationByUserIdAsync(string userId, CancellationToken cancellationToken)
        {
            var userRoleAssignments = await _roleAssignmentRepository.GetRoleAssignmentsByUserAsync(userId);

            var userRoles = userRoleAssignments.Select(x => x.Role.RoleType).ToList();

            var configurationList = new List <ConfigurationView>();

            foreach (var userRole in userRoles)
            {
                var roleRules = await _rulesConfigurationService.GetRulesAsync(cancellationToken);

                var configurationItem = roleRules
                                        .Roles
                                        .FirstOrDefault(role =>
                                                        role.RoleType.Equals(userRole, StringComparison.OrdinalIgnoreCase) &&
                                                        role.Definition.CanAssignRoles != null &&
                                                        role.Definition.CanAssignRoles.Count > 0);

                if (configurationItem == null)
                {
                    return(configurationList);
                }

                var assignableRoles = configurationItem.Definition.CanAssignRoles;

                foreach (var assignableRole in assignableRoles)
                {
                    var assignableRoleConfigurationItem = roleRules
                                                          .Roles
                                                          .FirstOrDefault(
                        role => role.RoleType.Equals(assignableRole, StringComparison.OrdinalIgnoreCase));

                    if (assignableRoleConfigurationItem == null)
                    {
                        continue;
                    }

                    configurationList.Add(new ConfigurationView
                    {
                        RoleType   = assignableRoleConfigurationItem.RoleType,
                        DataScopes = assignableRoleConfigurationItem
                                     .Definition
                                     .DataScopes
                                     .Select(ds => new DataScopeView
                        {
                            DataScopeInformation = ds.DataScopeInformation,
                            IsRequired           = ds.IsRequired,
                            MapTo       = ds.MapTo,
                            MultiSelect = ds.MultiSelect ?? false
                        }).ToList(),
                        IsInternal = assignableRoleConfigurationItem.Definition.IsInternal
                    });
                }
            }

            return(configurationList);
        }