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

fix(vue,php): Problem about renaming a space #893

Merged
merged 1 commit into from
Mar 26, 2024
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
7 changes: 6 additions & 1 deletion lib/Controller/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ public function rename(string $newGroupName,
|| str_starts_with($group->getGID(), 'SPACE-G-');
});

if (!empty($groups)) {
$groupsNameSearched = array_map(
fn ($group) => $group->getGID(),
$groups);

if (!empty($groups)
&& in_array($newGroupName, $groupsNameSearched)) {
return new JSONResponse(
'This group already exists. Please, change the name',
Http::STATUS_CONFLICT
Expand Down
65 changes: 61 additions & 4 deletions src/SpaceDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,23 @@ export default {
})

const groupKeys = Object.keys(space.groups)

groupKeys.forEach(key => {
const group = space.groups[key]
/**
* To fix a bug where the space is renamed to single
* then to plural (or inversely)
* This bug is present from release 3.0.2
*/
if (!this.checkSpaceNameIsEqual(group.displayName, oldSpaceName)) {
group.displayName = this.replaceSpaceName(group.displayName, oldSpaceName)
}
const newDisplayName = group.displayName.replace(oldSpaceName, newSpaceName)

// Renames group
this.$store.dispatch('renameGroup', {
name: newSpaceName,
gid: group.gid,
newGroupName: newDisplayName,
name: newSpaceName,
gid: group.gid,
newGroupName: newDisplayName,
})
})

Expand All @@ -233,6 +240,56 @@ export default {
showNotificationError('Error to rename space', text, 5000)
}
},
/**
* @param {string} groupname the displayname from a group
* @param {string} oldSpaceName the currently space name
* To fix a bug from release 3.0.2
*/
checkSpaceNameIsEqual(groupname, oldSpaceName) {
let spaceNameFiltered = ''

if (groupname.startsWith('U-')) {
spaceNameFiltered = groupname.replace('U-', '')
}

if (groupname.startsWith('WM-')) {
spaceNameFiltered = groupname.replace('WM-', '')
} else if (groupname.startsWith('GE-')) {
spaceNameFiltered = groupname.replace('GE-', '')
}

if (groupname.startsWith('G-')) {
spaceNameFiltered = groupname.replace('G-', '')
}

if (spaceNameFiltered === oldSpaceName) {
return true
}

return false
},
/**
* @param {string} groupname the displayname from a group
* @param {string} oldSpaceName the currently space name
* To fix a bug from release 3.0.2
*/
replaceSpaceName(groupname, oldSpaceName) {
const spaceNameSplitted = groupname
.split('-')
.filter(element => element)

if (spaceNameSplitted[0] === 'WM'
|| spaceNameSplitted[0] === 'U') {
spaceNameSplitted[1] = oldSpaceName
}

if (spaceNameSplitted[0] === 'G') {
const lengthMax = spaceNameSplitted.length - 1
spaceNameSplitted[lengthMax] = oldSpaceName
}

return spaceNameSplitted.join('-')
},
// Sets a space's quota
setSpaceQuota(quota) {
if (quota === null) {
Expand Down
Loading