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

Returns HTTP 409 if an organization exists on organization create #1925

Merged
merged 1 commit into from Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/dispatch/organization/views.py
Expand Up @@ -24,7 +24,8 @@
OrganizationUpdate,
OrganizationPagination,
)
from .service import create, get, update, add_user
from .service import create, get, get_by_name, update, add_user


router = APIRouter()

Expand All @@ -46,18 +47,16 @@ def create_organization(
current_user: DispatchUser = Depends(get_current_user),
):
"""Create a new organization."""
try:
organization = create(db_session=db_session, organization_in=organization_in)
except IntegrityError:
raise ValidationError(
[
ErrorWrapper(
ExistsError(msg="An organization with this name already exists."), loc="name"
)
],
model=OrganizationCreate,
organization = get_by_name(db_session=db_session, name=organization_in.name)
if organization:
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail=[{"msg": "An organization with this name already exists."}],
)

# create organization
organization = create(db_session=db_session, organization_in=organization_in)

# add creator as organization owner
add_user(
db_session=db_session, organization=organization, user=current_user, role=UserRoles.owner
Expand Down
13 changes: 13 additions & 0 deletions src/dispatch/static/dispatch/src/api.js
Expand Up @@ -62,6 +62,19 @@ instance.interceptors.response.use(
) {
return Promise.reject(err)
}

if (err.response.status == 409) {
let errorText = err.response.data.detail.map(({ msg }) => msg).join(" ")
store.commit(
"notification_backend/addBeNotification",
{
text: errorText,
type: "error",
},
{ root: true }
)
}

if (err.response.status == 422) {
let errorText = err.response.data.detail.map(({ msg }) => msg).join(" ")
store.commit(
Expand Down
@@ -1,6 +1,6 @@
<template>
<v-system-bar
v-if="currentOrganization.banner_enabled"
v-if="currentOrganization && currentOrganization.banner_enabled"
:color="currentOrganization.banner_color"
height="64px"
app
Expand Down