Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V8: Duplicate MemberGroup names cause MemberGroup mixup #11291

Merged
merged 5 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Umbraco.Web.UI/Umbraco/config/lang/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,7 @@ To manage your website, simply open the Umbraco backoffice and start adding cont
<key alias="mediaTypeSavedHeader">Media Type saved</key>
<key alias="memberTypeSavedHeader">Member Type saved</key>
<key alias="memberGroupSavedHeader">Member Group saved</key>
<key alias="memberGroupNameDuplicate">Another Member Group with the same name already exists</key>
<key alias="templateErrorHeader">Template not saved</key>
<key alias="templateErrorText">Please make sure that you do not have 2 templates with the same alias</key>
<key alias="templateSavedHeader">Template saved</key>
Expand Down
1 change: 1 addition & 0 deletions src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,7 @@ To manage your website, simply open the Umbraco backoffice and start adding cont
<key alias="mediaTypeSavedHeader">Media Type saved</key>
<key alias="memberTypeSavedHeader">Member Type saved</key>
<key alias="memberGroupSavedHeader">Member Group saved</key>
<key alias="memberGroupNameDuplicate">Another Member Group with the same name already exists</key>
<key alias="templateErrorHeader">Template not saved</key>
<key alias="templateErrorText">Please make sure that you do not have 2 templates with the same alias</key>
<key alias="templateSavedHeader">Template saved</key>
Expand Down
1 change: 1 addition & 0 deletions src/Umbraco.Web.UI/Umbraco/config/lang/fr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,7 @@ Pour gérer votre site, ouvrez simplement le backoffice Umbraco et commencez à
<key alias="mediaTypeSavedHeader">Type de média sauvegardé</key>
<key alias="memberTypeSavedHeader">Type de membre sauvegardé</key>
<key alias="memberGroupSavedHeader">Groupe de membres sauvegardé</key>
<key alias="memberGroupNameDuplicate">Un autre groupe de membres existe déjà avec le même nom</key>
<key alias="templateErrorHeader">Modèle non sauvegardé</key>
<key alias="templateErrorText">Assurez-vous de ne pas avoir 2 modèles avec le même alias.</key>
<key alias="templateSavedHeader">Modèle sauvegardé</key>
Expand Down
1 change: 1 addition & 0 deletions src/Umbraco.Web.UI/Umbraco/config/lang/nl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,7 @@ Echter, Runway biedt een gemakkelijke basis om je snel op weg te helpen. Als je
<key alias="mediaTypeSavedHeader">Mediatype opgeslagen</key>
<key alias="memberTypeSavedHeader">Ledentype opgeslagen</key>
<key alias="memberGroupSavedHeader">Ledengroep opgeslagen</key>
<key alias="memberGroupNameDuplicate">Er bestaat al een andere ledengroep met dezelfde naam</key>
<key alias="templateErrorHeader">Sjabloon niet opgeslagen</key>
<key alias="templateErrorText">Controleer dat je geen 2 sjablonen met dezelfde naam hebt</key>
<key alias="templateSavedHeader">Sjabloon opgeslagen</key>
Expand Down
38 changes: 31 additions & 7 deletions src/Umbraco.Web/Editors/MemberGroupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ public MemberGroupDisplay GetEmpty()
return Mapper.Map<IMemberGroup, MemberGroupDisplay>(item);
}

public bool IsMemberGroupNameUnique(int id, string oldName, string newName)
{
if (newName == oldName)
return true; // name hasn't changed

var service = Services.MemberGroupService;
var memberGroup = service.GetByName(newName);
if (memberGroup == null)
return true; // no member group found

return memberGroup.Id == id;
}

public MemberGroupDisplay PostSave(MemberGroupSave saveModel)
{
var service = Services.MemberGroupService;
Expand All @@ -146,16 +159,27 @@ public MemberGroupDisplay PostSave(MemberGroupSave saveModel)
throw new HttpResponseException(HttpStatusCode.NotFound);
}

memberGroup.Name = saveModel.Name;
service.Save(memberGroup);
if (IsMemberGroupNameUnique(memberGroup.Id, memberGroup.Name, saveModel.Name))
{
memberGroup.Name = saveModel.Name;
service.Save(memberGroup);

var display = Mapper.Map<IMemberGroup, MemberGroupDisplay>(memberGroup);
var display = Mapper.Map<IMemberGroup, MemberGroupDisplay>(memberGroup);
display.AddSuccessNotification(
Services.TextService.Localize("speechBubbles", "memberGroupSavedHeader"),
string.Empty);

display.AddSuccessNotification(
Services.TextService.Localize("speechBubbles", "memberGroupSavedHeader"),
string.Empty);
return display;
}
else
{
var display = Mapper.Map<IMemberGroup, MemberGroupDisplay>(memberGroup);
display.AddErrorNotification(
Services.TextService.Localize("speechBubbles", "memberGroupNameDuplicate"),
string.Empty);

return display;
return display;
}
}
}
}