Skip to content

Commit

Permalink
fix(vue,php): Problem about renaming a space
Browse files Browse the repository at this point in the history
When we rename a space from plural to single (or inversely) all groups
are bad renamed.

Signed-off-by: Baptiste Fotia <[email protected]>
  • Loading branch information
zak39 committed Mar 26, 2024
1 parent ee5c95c commit 569c896
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
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

0 comments on commit 569c896

Please sign in to comment.