nearform/udaru

Request: Unique Team and Policy Names

Closed this issue · 6 comments

On a project I am working on there is a requirement to have unique team and policy names within an organisation.

Is this something Udaru should implement?

we're implementing team search so this could solve from application point of view i.e. search for team name before allowing add?

@cianfoley-nearform

This does not really do the original request justice - requiring a client to search first to check for existence of a team/policy to decide whether to create or not is not really what was being driven at.

For context - one of our clients has raised this as a request - and as a part of this we would have a project that would be importing from CSVs (users/teams/policies) which number in the high hundreds (first initial case 800 items). Searching first would make this process a much larger task with a greater surface area for errors - especially as we would have the creation then assignment operations in the process.

If it is the decision of the project to allow teams/policies to have the same name over and over in a single organisation - then so be it a workaround would need to be found but can we get to a decision to not implement this request.

@dberesford @mihaidma

Hi Shaun,

Sorry I wasn't fobbing you off just asking a question, apologies if it didn't do request justice...

How would you see this working? Pass in insert payload of X and get an conflict returned with list of conflicting names?

A simple option that might work would be on your installation database, is put constraints on the columns you need to be unique e.g. on team it would be unique id and unique name+org constraints,

scripts could be run on db for this, however our error handling would need to reflect this as currently on conflict we simply throw up an ID clash for users and teams (policies is more generic)...

so if we took out the specific case and let the database throw up the error we'd get something like

{
"statusCode": 400,
"error": "Bad Request",
"message": "duplicate key value violates unique constraint "unique name""
}

where the constraint unique_name is based on username and org together being unique...

the unique id would then respond like

{
"statusCode": 400,
"error": "Bad Request",
"message": "duplicate key value violates unique constraint "users_id_key""
}

This should probably be 409 response too...

@ShaunBaker, would this be acceptable?

The err.detail spits this out for the two test constraints I set up, which might be more useful...

{
"statusCode": 400,
"error": "Bad Request",
"message": "Key (name, org_id)=(MetaUser1, WONKA) already exists."
}

{
"statusCode": 400,
"error": "Bad Request",
"message": "Key (id)=(MetaUser1) already exists."
}

Catered for in this commit: ece3eed