/// <inheritdoc /> public Task <IdentityResult> UpdateAsync(UmbracoIdentityRole role, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (role == null) { throw new ArgumentNullException(nameof(role)); } if (!int.TryParse(role.Id, NumberStyles.Integer, CultureInfo.InvariantCulture, out int roleId)) { return(Task.FromResult(IdentityResult.Failed(_intParseError))); } IMemberGroup memberGroup = _memberGroupService.GetById(roleId); if (memberGroup != null) { if (MapToMemberGroup(role, memberGroup)) { _memberGroupService.Save(memberGroup); } return(Task.FromResult(IdentityResult.Success)); } else { return(Task.FromResult(IdentityResult.Failed(_memberGroupNotFoundError))); } }
/// <summary> /// Gets the member group json for the member group id /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult <MemberGroupDisplay> GetById(int id) { IMemberGroup memberGroup = _memberGroupService.GetById(id); if (memberGroup == null) { return(NotFound()); } MemberGroupDisplay dto = _umbracoMapper.Map <IMemberGroup, MemberGroupDisplay>(memberGroup); return(dto); }
/// <summary> /// Refresh the rules so any changes are reflected immediately without site restart /// </summary> private void RefreshRules() { using (var context = _factory.EnsureUmbracoContext()) { Rules = new List <KeepOutRule>(); RulesPages = new List <string>(); var rulesFolder = context.UmbracoContext.Content.GetById(KeepOutRulesFolderId); var rules = rulesFolder.Children .Where(x => x.IsPublished() && x.ContentType.Alias == "keepOutSecurityRule") .OrderBy(x => x.CreateDate); foreach (var rule in rules) { var coverageColour = rule.Properties.Single(x => x.Alias == "coverageColour").GetValue() as ColorPickerValueConverter.PickedColor; var deniedMemberGroups = new List <string>(); var memberGroupIds = rule.Properties.Single(x => x.Alias == "deniedMemberGroups").GetValue().ToString().Split(new [] { ',' }).ToList(); foreach (var memberGroupId in memberGroupIds) { var intMemberGroupId = int.Parse(memberGroupId); var memberGroup = _memberGroupService.GetById(intMemberGroupId); deniedMemberGroups.Add(memberGroup.Name); } var noAccessPage = rule.Properties.Single(x => x.Alias == "noAccessPage").GetValue() as IPublishedContent; var pageToSecure = rule.Properties.Single(x => x.Alias == "pageToSecure").GetValue() as IPublishedContent; var keepOutRule = new KeepOutRule { CoverageColour = "keepout-" + coverageColour.Label, DeniedMemberGroups = deniedMemberGroups, NoAccessPage = noAccessPage.Id, PageToSecure = pageToSecure.Id }; Rules.Add(keepOutRule); RulesPages.Add(keepOutRule.PageToSecure.ToString()); } } }
public object Convert(object value) { if (int.TryParse(value.ToString(), out var id)) { return(_memberGroupService.GetById(id).Name); } return(null); }
public object Convert(object value, Dictionary <string, object> options = null) { if (int.TryParse(value.ToString(), out var id)) { return(_memberGroupService.GetById(id).Name); } return(null); }
public Task UpdateAsync(T role) { if (role == null) { throw new ArgumentNullException("role"); } var memberGroup = _memberGroupService.GetById(role.Id); if (memberGroup != null) { if (MapToMemberGroup(role, memberGroup)) { _memberGroupService.Save(memberGroup); } } return(Task.FromResult(0)); }
public async Task <IHttpActionResult> Delete(int groupId) { var group = _memberGroupService.GetById(groupId); await _permissionsService.DeletePermissionsForMemberGroupAsync(groupId); _intranetMemberGroupService.Delete(groupId); return(Ok()); }
public virtual bool Save(int id, string name) { if (string.IsNullOrWhiteSpace(name)) { return(false); } var groupByName = _memberGroupService.GetByName(name); if (groupByName != null && groupByName.Id != id) { return(false); } var memberGroup = _memberGroupService.GetById(id); memberGroup.Name = name; _memberGroupService.Save(memberGroup); ClearCache(); return(true); }