mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2025-08-31 22:50:43 +00:00
feat: Truncate Old Name
This commit is contained in:
parent
18a979ea4e
commit
98a63e8e96
2 changed files with 7 additions and 4 deletions
|
@ -739,12 +739,15 @@ export class RoleService implements OnApplicationShutdown, OnModuleInit {
|
|||
|
||||
@bindThis
|
||||
public async clone(role: MiRole, moderator?: MiUser): Promise<MiRole> {
|
||||
let newName = `${role.name} (cloned)`;
|
||||
const suffix = ' (cloned)';
|
||||
let newName = role.name;
|
||||
|
||||
if (newName.length > 256) {
|
||||
newName = newName.slice(0, 256);
|
||||
if (newName.length > 256 - suffix.length) {
|
||||
newName = newName.slice(0, 256 - suffix.length);
|
||||
}
|
||||
|
||||
newName += suffix;
|
||||
|
||||
return this.create({
|
||||
...role,
|
||||
name: newName,
|
||||
|
|
|
@ -1025,7 +1025,7 @@ describe('RoleService', () => {
|
|||
|
||||
expect(clonedRole).toBeDefined();
|
||||
expect(clonedRole.id).not.toBe(role.id);
|
||||
expect(clonedRole.name).toBe(`${role.name} (`);
|
||||
expect(clonedRole.name.endsWith(' (cloned)')).toBeTruthy();
|
||||
expect(clonedRole.name.length).toBe(256);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue