message: Rename project default group/user if project name changes
diff: @@ -397,6 +397,7 @@ const updateProject = async (
  {
  sqlClient,
  hasPermission,
  + dataSources,
  },
  ) => {
  await hasPermission('project', 'update', {
  @@ -415,6 +416,8 @@ const updateProject = async (
  }
  }
  + const oldProject = await Helpers(sqlClient).getProjectById(id);
  +
  // TODO If the privateKey changes, automatically remove the old one from the
  // default user and link the new one.
  @@ -469,6 +472,31 @@ const updateProject = async (
  }),
  );
  + // Rename the default group and user
  + if (patch.name && oldProject.name !== patch.name) {
  + try {
  + const group = await dataSources.GroupModel.loadGroupByName(`project-${oldProject.name}`);
  + await dataSources.GroupModel.updateGroup({
  + id: group.id,
  + name: `project-${patch.name}`,
  + });
  + } catch (err) {
  + logger.error(`Could not rename default group for project ${patch.name}: ${err.message}`);
  + }
  +
  + try {
  + const user = await dataSources.UserModel.loadUserByUsername(`default-user@${oldProject.name}`);
  + await dataSources.UserModel.updateUser({
  + id: user.id,
  + email: `default-user@${patch.name}`,
  + username: `default-user@${patch.name}`,
  + comment: `autogenerated user for project ${patch.name}`,
  + });
  + } catch (err) {
  + logger.error(`Could not rename default user for project ${patch.name}: ${err.message}`);
  + }
  + }
  +
  // if (typeof name === 'string' && name !== originalName) {
  // const groupId = await KeycloakOperations.findGroupIdByName(originalName);
  