public UserGroup CreateUserGroup(TenantGroup tenantGroup) { ValidateGroup(tenantGroup); var groupAlias = tenantGroup.Name.Sanitize(); UserGroup group = (UserGroup)userService.GetUserGroupByAlias(groupAlias); try { group = new UserGroup(1, groupAlias, tenantGroup.Name, Enumerable.Empty <string>(), "icon-umb-members") { Permissions = tenantGroup.Permissions, StartContentId = tenantGroup.StartContentId, StartMediaId = tenantGroup.StartMediaId }; foreach (var section in tenantGroup.AllowedSectionAliases) { group.AddAllowedSection(section); } userService.Save(group); ConnectorContext.AuditService.Add(AuditType.New, -1, group.Id, "User Group", $"User Group {group.Name} has been created"); return(group); } catch (Exception ex) { logger.Error(typeof(UserGroupService), ex.Message); logger.Error(typeof(UserGroupService), ex.StackTrace); throw; } }
public JsonRpcResponseData CreateGroup(TenantGroup payload, ApiAuthorization authorization) { SetupAuth(); IsValidRequest(authorization.AppId, authorization.ApiKey); var apiController = new ControllerService(); try { var groupId = apiController.CreateGroup(payload); return(new JsonRpcResponseData { Message = $"Group {payload.Name} Created", Status = JsonRpcResponseData.OK, TenantUid = payload.TenantUid.ToString(), Data = new { groupId } }); } catch (System.Exception ex) { throw HandleException(ex); } }
public void ValidateGroup(TenantGroup group) { var g = userService.GetUserGroupByAlias(group.Name); if (g != null) { throw new TenantException(ExceptionCode.GroupAlreadyExists.CodeToString(), ExceptionCode.GroupAlreadyExists, group.TenantUid, group.Name); } }
public IUserGroup EditGroup(string oldGroupName, TenantGroup newGroup) { var group = userService.GetUserGroupByAlias(oldGroupName.Sanitize()); if (group == null) { throw new TenantException(ExceptionCode.GroupDoesNotExist.CodeToString(), ExceptionCode.GroupDoesNotExist, oldGroupName); } if (!string.IsNullOrEmpty(newGroup.Name)) { ValidateGroup(newGroup.Name); } try { group.Name = string.IsNullOrEmpty(newGroup.RenameGroupTo) ? group.Name : newGroup.RenameGroupTo; group.Alias = string.IsNullOrEmpty(newGroup.RenameGroupTo) ? group.Alias : newGroup.RenameGroupTo.Sanitize(); group.Permissions = newGroup.Permissions.Any() ? newGroup.Permissions : group.Permissions; if (newGroup.AllowedSectionAliases.Any() && !string.Join(",", newGroup.AllowedSectionAliases.ToArray()).Equals(string.Join(",", group.AllowedSections))) { group.ClearAllowedSections(); foreach (var section in newGroup.AllowedSectionAliases) { group.AddAllowedSection(section); } } if (newGroup.StartContentId.HasValue && !newGroup.StartContentId.Value.Equals(group.StartContentId)) { group.StartContentId = newGroup.StartContentId.Value; } if (newGroup.StartMediaId.HasValue && !newGroup.StartMediaId.Value.Equals(group.StartMediaId)) { group.StartMediaId = newGroup.StartMediaId.Value; } userService.Save(group); ConnectorContext.AuditService.Add(AuditType.Save, -1, group.Id, "User Group", $"User Group {group.Id} has been renamed from '{oldGroupName}' to '{newGroup.Name}'"); return(group); } catch (Exception ex) { logger.Error(typeof(UserGroupService), ex.Message); logger.Error(typeof(UserGroupService), ex.StackTrace); throw; } }
public string CreateGroup(TenantGroup group) { return(userGroupService.CreateUserGroup(group).Id.ToString()); }
public ExtendedTenant EditTenant(TenantData tenant, TenantUser user = null, TenantGroup group = null) { var mediaService = new HomeMediaNode(ConnectorContext.MediaService, ConnectorContext.Logger, ConnectorContext.ContentTypeBaseService); var tenantNode = nodeHelper.GetTenantRoot(tenant.TenantUId); languageService.CreateDictionary(tenant); if (user != null) { userGroupService.UpdateUser(user); } IUserGroup g = null; if (group != null) { if (!string.IsNullOrWhiteSpace(group.RenameGroupTo)) { g = userGroupService.EditGroup(group.Name, group); } } else { if (!string.IsNullOrEmpty(tenant.ReadOnlyGroupAlias)) { g = userGroupService.GetUserGroup(tenant.ReadOnlyGroupAlias); } } var mediaId = mediaService.RenameMediaHome(tenant, user); tenant.TenantPreferences.PaymentSettings = tenant.PaymentSettings; //little hack to match total coding system submission to umbraco properties tenant.PaymentSettings = null; var extended = new ExtendedTenant { Tenant = tenant, StartContentId = tenantNode.Id, StartMediaId = mediaId, AllowedSectionAliases = g?.AllowedSections, Permissions = g?.Permissions, }; homeNode.EditTenant(tenant); nodeHelper.AddLanguageVersionToNode(extended.Tenant); extended.Tenant.Username = user?.Username; extended.Tenant.Name = user?.Name; extended.Tenant.Email = user?.Email; extended.Tenant.Password = user != null ? "*********" : null; extended.Tenant.Group = group?.Name; extended.UserId = user?.AssignedUmbracoUserId ?? 0; if (!string.IsNullOrEmpty(extended.Tenant.AppId) || !string.IsNullOrEmpty(extended.Tenant.ApiKey)) { var apiService = new ApiKeysService(this.database); apiService.UpdateApiForTenant(extended); } if (SaveAndPublish) { new NodeHelper().TryPublishSite(tenantNode.Id); } return(extended); }
public JsonRpcResponseData EditTenant(TenantData tenant, ApiAuthorization authorization, TenantUser user = null, TenantGroup group = null) { SetupAuth(); IsValidRequest(authorization.AppId, authorization.ApiKey); var apiController = new ControllerService(); try { var extended = apiController.EditTenant(tenant, user, group); return(new JsonRpcResponseData { Message = "Tenant edited", Status = JsonRpcResponseData.OK, TenantUid = extended.Tenant.TenantUId.ToString(), Data = new { extended } }); } catch (System.Exception ex) { throw HandleException(ex); } }