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

[dashboard][server] Make all project slugs unique within a team or user account by adding a unique suffix #6883

Merged
merged 1 commit into from
Nov 26, 2021

Conversation

jankeromnes
Copy link
Contributor

Description

Make all project slugs unique within a team or user account by adding a unique suffix.

Related Issue(s)

Fixes #6600

How to test

  1. Create two repositories with the same name, but under different owners (or Git providers), e.g. username/test and org/test
  2. Add the two repos as Projects (either under your personal account, or a team, but both Projects should be in the same location)
  3. Verify the two Projects have different slugs (e.g. the first added should have the slug test, and the second one test-1)

Release Notes

[dashboard][server] Make all project slugs unique within a team or user account by adding a unique suffix

Documentation

/uncc

@roboquat roboquat added release-note team: webapp Issue belongs to the WebApp team size/S labels Nov 25, 2021
@jankeromnes
Copy link
Contributor Author

jankeromnes commented Nov 25, 2021

Whoops, the build is currently broken (#6876) so no deployment yet.

Will give it another kick once the build is fixed. 🙂 EDIT: ✅

@jankeromnes jankeromnes force-pushed the jx/unique-project-slug branch from dcc8b93 to cd30648 Compare November 25, 2021 11:16
@jankeromnes
Copy link
Contributor Author

jankeromnes commented Nov 25, 2021

Let's try this again. 🎰

/werft run

👍 started the job as gitpod-build-jx-unique-project-slug.2

@jankeromnes
Copy link
Contributor Author

jankeromnes commented Nov 25, 2021

Platform got fixed by platform team, trying again:

/werft run

👍 started the job as gitpod-build-jx-unique-project-slug.3

@@ -95,9 +95,17 @@ export class ProjectsService {
if (projects.length > 0) {
throw new Error("Project for repository already exists.");
}
// If the desired project slug already exists in this team or user account, add a unique suffix to avoid collisions.
Copy link
Contributor

@JanKoehnlein JanKoehnlein Nov 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am paranoid here, but wouldn't it be safer against collisions the other way around:

  1. Create the project
  2. Read user existing projects and increment the suffix and update until unique

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you worried about two projects with the same name being added at the exact same time?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of. As the slug yields the URI, a collision would not be nice. Maybe this is not so important for projects within teams, but more likely for teams

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For teams, team creation fails if there is a collision. The code is here:

if (!name) {
throw new Error('Team name cannot be empty');
}
if (!/^[A-Za-z0-9 '_-]+$/.test(name)) {
throw new Error('Please choose a team name containing only letters, numbers, -, _, \', or spaces.');
}
const slug = name.toLocaleLowerCase().replace(/[ ']/g, '-');
if (FORBIDDEN_SLUGS.indexOf(slug) !== -1) {
throw new Error('Creating a team with this name is not allowed');
}
const userRepo = await this.getUserRepo();
const existingUsers = await userRepo.query('SELECT COUNT(id) AS count FROM d_b_user WHERE fullName LIKE ? OR name LIKE ?', [ name, slug ]);
if (Number.parseInt(existingUsers[0].count) > 0) {
throw new Error('A team cannot have the same name as an existing user');
}
const teamRepo = await this.getTeamRepo();
const existingTeam = await teamRepo.findOne({ slug, deleted: false, markedDeleted: false });
if (!!existingTeam) {
throw new Error('A team with this name already exists');
}

@JanKoehnlein
Copy link
Contributor

/lgtm

@roboquat
Copy link
Contributor

LGTM label has been added.

Git tree hash: 5fb471b813e84895f049501dfb87c99e5e9ba653

@roboquat
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JanKoehnlein

Associated issue: #6600

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@roboquat roboquat merged commit 473274c into main Nov 26, 2021
@roboquat roboquat deleted the jx/unique-project-slug branch November 26, 2021 14:50
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved deployed: webapp Meta team change is running in production deployed Change is completely running in production release-note size/S team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Two different projects can be added with the same slug
3 participants