public async Task <List <UILocalisationTextDto> > GetUILocalisationTextsForCurrentContextAsync() { var groups = await GetPermittedGroupIdsForCurrentUserAsync(true); var allTexts = new List <UILocalisationTextDto>(); //Iterate group data stores and collect relevant data. foreach (var groupId in groups) { var dataContext = _groupDataContextFactory.CreateGroupDataContext(groupId); var texts = await dataContext.GetDocumentsAsync <LocalisationText, UILocalisationTextDto>(q => q.Where(t => t.Culture == _requestContext.Culture || t.Culture == "*") .OrderBy(t => t.Priority) .Select(t => new UILocalisationTextDto { Key = t.Key, GroupId = t.GroupId, Culture = t.Culture, Section = t.Section, Priority = t.Priority, Value = t.Value })); allTexts.AddRange(texts); } allTexts = allTexts.OrderBy(t => t.Priority).ToList(); return(allTexts); }
private async Task <ConfigurationSetting> GetConfigurationSettingAsync(string key, string groupId, string culture, string section) { IGroupDataContext dataContext = _groupDataContextFactory.CreateGroupDataContext(groupId); var config = await dataContext.FirstOrDefaultAsync <ConfigurationSetting, ConfigurationSetting>(q => q.Where(c => (c.Culture == culture || c.Culture == "*") && (c.Section == section || c.Section == "*") && c.Key == key) .OrderBy(c => c.Priority)); return(config); }
private async Task <LocalisationText> GetLocalisationTextAsync(string key, string groupId, string culture, string section) { IGroupDataContext dataContext = _groupDataContextFactory.CreateGroupDataContext(groupId); var text = await dataContext.FirstOrDefaultAsync <LocalisationText, LocalisationText>(q => q.Where(c => (c.Culture == culture || c.Culture == "*") && (c.Section == section || c.Section == "*") && c.Key == key) .OrderBy(c => c.Priority)); return(text); }
private async Task <AlertTemplate> GetTemplateAsync(string key, string groupId, string culture, string channel) { IGroupDataContext dataContext = _groupDataContextFactory.CreateGroupDataContext(groupId); var text = await dataContext.FirstOrDefaultAsync <AlertTemplate, AlertTemplate>(q => q.Where(c => (c.Culture == culture || c.Culture == "*") && c.Section == "*" && c.Key == key && c.Channel == channel) .OrderBy(c => c.Priority)); return(text); }
public virtual async Task <List <PermissionConfigDto> > GetGroupRolesForSpecificDomainAsync(string domainPrefix, string groupId) { var _groupDataContext = _groupDataContextFactory.CreateGroupDataContext(groupId); var permissions = (await _groupDataContext.GetDocumentsAsync <PermissionConfig, PermissionConfig>(q => q)).ToList() .Where(p => p.Permissions.Where(ps => ps.StartsWith(domainPrefix)).Any()). Select(pc => new PermissionConfigDto() { GroupId = pc.GroupId, Role = pc.Role, Permissions = pc.Permissions.Where(s => s.StartsWith(domainPrefix)).Select(c => c).ToList() }).ToList(); return(permissions); }
/// <summary> /// Look through all permitted tenant partitions and collect all objects to be exported. /// </summary> protected async Task <IEnumerable <T> > CollectPermittedObjectsAsync(IEnumerable <string> groupIds) { var allResults = new List <T>(); //Iterate group data stores and collect relevant data. foreach (var groupId in groupIds) { var dataContext = _groupDataContextFactory.CreateGroupDataContext(groupId); var results = await dataContext.GetDocumentsAsync(_query); allResults.AddRange(results); } return(allResults); }
private async Task <List <string> > GetEffectivePermissionsForUserByGroup(User user, string contextGroupId = null) { var allPermissions = new List <string>(); List <UserGroupRole> userGroupRoleList = user.GroupRoles; //Check if "ANY" to prevent group filteration if (contextGroupId != null && contextGroupId != "ANY") { userGroupRoleList = userGroupRoleList.Where(c => c.Group == contextGroupId).ToList(); } var roleGroups = userGroupRoleList.GroupBy(cr => cr.Group, cr => cr.Role); foreach (var roleGroup in roleGroups) { string groupId = roleGroup.Key; var roles = roleGroup.ToList(); //The ALL_ROLES role. Whatever permissions defined at this role should merge //with permissions defined at the specific named role. roles.Add("*"); //Check whether the group has their own LIST_ROLES defined. var groupDataContext = _groupDataContextFactory.CreateGroupDataContext(groupId); var groupListRolesDefined = await groupDataContext.AnyAsync <Lookup>(q => q.Where(l => l.Key == SystemKeys.LookupKeys.LIST_ROLES)); foreach (string role in roles) { var config = await groupDataContext.FirstOrDefaultAsync <PermissionConfig, PermissionConfig>(q => q.Where(pc => pc.Role == role)); //Fallback to system-level permissions only if group does not have their own LIST_ROLES defined. if (config == null && !groupListRolesDefined) { config = await _systemDataContext.FirstOrDefaultAsync <PermissionConfig, PermissionConfig>(q => q.Where(pc => pc.Role == role)); } if (config != null) { allPermissions.AddRange(config.Permissions.Select(p => $"{groupId}:{p}")); } } } return(allPermissions.OrderBy(s => s).Distinct().ToList()); }