Skip to content

Commit

Permalink
Disable rename alias of system user groups
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmusjp authored and nul800sebastiaan committed Sep 26, 2019
1 parent 885f0f0 commit 6beb844
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ Use this directive to construct a header inside the main editor window.
@param {string=} icon Show and edit the content icon. Opens an overlay to change the icon.
@param {boolean=} hideIcon Set to <code>true</code> to hide icon.
@param {string=} alias show and edit the content alias.
@param {boolean=} aliasLocked Set to <code>true</code> to lock the alias.
@param {boolean=} hideAlias Set to <code>true</code> to hide alias.
@param {string=} description Add a description to the content.
@param {boolean=} hideDescription Set to <code>true</code> to hide description.
Expand All @@ -207,7 +208,6 @@ Use this directive to construct a header inside the main editor window.
function EditorHeaderDirective(editorService) {

function link(scope) {

scope.vm = {};
scope.vm.dropdownOpen = false;
scope.vm.currentVariant = "";
Expand Down Expand Up @@ -262,6 +262,7 @@ Use this directive to construct a header inside the main editor window.
icon: "=",
hideIcon: "@",
alias: "=",
aliasLocked: "<",
hideAlias: "=",
description: "=",
hideDescription: "@",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
color: @gray-3;
}

input.umb-locked-field__input {
input.umb-locked-field__input,
.umb-locked-field__text {
background: rgba(255, 255, 255, 0); // if using transparent it will hide the text in safari
border-color: transparent !important;
font-size: 13px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
ng-if="!hideAlias"
alias="$parent.alias"
alias-from="$parent.name"
enable-lock="true"
enable-lock="aliasLocked !== true"
validation-position="'right'"
server-validation-field="Alias">
</umb-generate-alias>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div>
<span ng-show="!enableLock">{{ alias }}</span>
<span class="umb-locked-field__text" ng-show="!enableLock">{{ alias }}</span>
<div ng-show="enableLock">
<umb-locked-field
locked="locked"
Expand Down
1 change: 1 addition & 0 deletions src/Umbraco.Web.UI.Client/src/views/users/group.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<umb-editor-header
name="vm.userGroup.name"
alias="vm.userGroup.alias"
alias-locked="vm.userGroup.isSystemUserGroup"
icon="vm.userGroup.icon"
hide-description="true"
on-back="vm.goToPage(vm.breadcrumbs[0])"
Expand Down
13 changes: 13 additions & 0 deletions src/Umbraco.Web/Editors/Filters/UserGroupValidateAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ public override void OnActionExecuting(HttpActionContext actionContext)
actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
return;
}

if (persisted.Alias != userGroupSave.Alias)
{
if (persisted.Alias == Constants.Security.AdminGroupAlias
|| persisted.Alias == Constants.Security.SensitiveDataGroupAlias
|| persisted.Alias == Constants.Security.TranslatorGroupAlias)
{
var message = $"User group with alias: {persisted.Alias} cannot be changed";
actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.BadRequest, message);
return;
}
}

//map the model to the persisted instance
Mapper.Map(userGroupSave, persisted);
break;
Expand Down
6 changes: 6 additions & 0 deletions src/Umbraco.Web/Models/ContentEditing/UserGroupBasic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@ public UserGroupBasic()
/// </summary>
[DataMember(Name = "userCount")]
public int UserCount { get; set; }

/// <summary>
/// Is the user group a system group e.g. "Administrators", "Sensitive data" or "Translators"
/// </summary>
[DataMember(Name = "isSystemUserGroup")]
public bool IsSystemUserGroup { get; set; }
}
}
18 changes: 11 additions & 7 deletions src/Umbraco.Web/Models/Mapping/UserMapDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private static void Map(IProfile source, ContentEditing.UserProfile target, Mapp
}

// Umbraco.Code.MapAll -ContentStartNode -UserCount -MediaStartNode -Key -Sections
// Umbraco.Code.MapAll -Notifications -Udi -Trashed -AdditionalData
// Umbraco.Code.MapAll -Notifications -Udi -Trashed -AdditionalData -IsSystemUserGroup
private void Map(IReadOnlyUserGroup source, UserGroupBasic target, MapperContext context)
{
target.Alias = source.Alias;
Expand All @@ -147,11 +147,11 @@ private void Map(IReadOnlyUserGroup source, UserGroupBasic target, MapperContext
target.Name = source.Name;
target.ParentId = -1;
target.Path = "-1," + source.Id;
MapUserGroupBasic(target, source.AllowedSections, source.StartContentId, source.StartMediaId, context);
MapUserGroupBasic(target, source.Alias, source.AllowedSections, source.StartContentId, source.StartMediaId, context);
}

// Umbraco.Code.MapAll -ContentStartNode -MediaStartNode -Sections -Notifications
// Umbraco.Code.MapAll -Udi -Trashed -AdditionalData
// Umbraco.Code.MapAll -Udi -Trashed -AdditionalData -IsSystemUserGroup
private void Map(IUserGroup source, UserGroupBasic target, MapperContext context)
{
target.Alias = source.Alias;
Expand All @@ -162,7 +162,7 @@ private void Map(IUserGroup source, UserGroupBasic target, MapperContext context
target.ParentId = -1;
target.Path = "-1," + source.Id;
target.UserCount = source.UserCount;
MapUserGroupBasic(target, source.AllowedSections, source.StartContentId, source.StartMediaId, context);
MapUserGroupBasic(target, source.Alias, source.AllowedSections, source.StartContentId, source.StartMediaId, context);
}

// Umbraco.Code.MapAll -Udi -Trashed -AdditionalData -AssignedPermissions
Expand Down Expand Up @@ -198,7 +198,7 @@ private static void Map(EntitySlim source, AssignedContentPermissions target, Ma
}

// Umbraco.Code.MapAll -ContentStartNode -MediaStartNode -Sections -Notifications -Udi
// Umbraco.Code.MapAll -Trashed -AdditionalData -Users -AssignedPermissions
// Umbraco.Code.MapAll -Trashed -AdditionalData -Users -AssignedPermissions -IsSystemUserGroup
private void Map(IUserGroup source, UserGroupDisplay target, MapperContext context)
{
target.Alias = source.Alias;
Expand All @@ -211,7 +211,7 @@ private void Map(IUserGroup source, UserGroupDisplay target, MapperContext conte
target.Path = "-1," + source.Id;
target.UserCount = source.UserCount;

MapUserGroupBasic(target, source.AllowedSections, source.StartContentId, source.StartMediaId, context);
MapUserGroupBasic(target, source.Alias, source.AllowedSections, source.StartContentId, source.StartMediaId, context);

//Important! Currently we are never mapping to multiple UserGroupDisplay objects but if we start doing that
// this will cause an N+1 and we'll need to change how this works.
Expand Down Expand Up @@ -334,8 +334,12 @@ private void Map(IUser source, UserDetail target, MapperContext context)

// helpers

private void MapUserGroupBasic(UserGroupBasic target, IEnumerable<string> sourceAllowedSections, int? sourceStartContentId, int? sourceStartMediaId, MapperContext context)
private void MapUserGroupBasic(UserGroupBasic target, string alias, IEnumerable<string> sourceAllowedSections, int? sourceStartContentId, int? sourceStartMediaId, MapperContext context)
{
target.IsSystemUserGroup = alias == Constants.Security.AdminGroupAlias
|| alias == Constants.Security.TranslatorGroupAlias
|| alias == Constants.Security.SensitiveDataGroupAlias;

var allSections = _sectionService.GetSections();
target.Sections = context.MapEnumerable<ISection, Section>(allSections.Where(x => sourceAllowedSections.Contains(x.Alias)));

Expand Down

0 comments on commit 6beb844

Please sign in to comment.