-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
Whoops, the build is currently broken (#6876) so no deployment yet. Will give it another kick once the build is fixed. 🙂 EDIT: ✅ |
…er account by adding a unique suffix
dcc8b93
to
cd30648
Compare
Let's try this again. 🎰 /werft run 👍 started the job as gitpod-build-jx-unique-project-slug.2 |
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. |
There was a problem hiding this comment.
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:
- Create the project
- Read user existing projects and increment the suffix and update until unique
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
gitpod/components/gitpod-db/src/typeorm/team-db-impl.ts
Lines 125 to 144 in 5d751e3
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'); | |
} |
/lgtm |
LGTM label has been added. Git tree hash: 5fb471b813e84895f049501dfb87c99e5e9ba653
|
[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 |
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
username/test
andorg/test
test
, and the second onetest-1
)Release Notes
Documentation
/uncc