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

[WIP] Bugfix/organization switching #2599

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/dispatch/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class DispatchUserOrganization(Base, TimeStampMixin):
organization_id = Column(Integer, ForeignKey(Organization.id), primary_key=True)
organization = relationship(Organization, backref="users")

default = Column(Boolean, default=False)
role = Column(String, default=UserRoles.member)


Expand All @@ -100,7 +101,6 @@ class DispatchUserProject(Base, TimeStampMixin):
project = relationship(Project, backref="users")

default = Column(Boolean, default=False)

role = Column(String, nullable=False, default=UserRoles.member)


Expand Down Expand Up @@ -163,7 +163,6 @@ class UserUpdate(DispatchBase):
password: Optional[str] = Field(None, nullable=True)
projects: Optional[List[UserProject]]
organizations: Optional[List[UserOrganization]]
role: Optional[str] = Field(None, nullable=True)

@validator("password", pre=True)
def hash(cls, v):
Expand Down
12 changes: 5 additions & 7 deletions src/dispatch/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ def update_user(
detail=[{"msg": "A user with this id does not exist."}],
)

if user_in.role:
user_organization_role = user.get_organization_role(organization)
# allow considerations for updating their own preferences
user_organization_role = user.get_organization_role(organization)
if current_user.id == user_id:
pass
else:
if user_organization_role != user_in.role:
current_user_organization_role = current_user.get_organization_role(organization)
if current_user_organization_role != UserRoles.owner:
Expand All @@ -118,11 +121,6 @@ def update_user(
],
)

# add organization information
user_in.organizations = [
UserOrganization(role=user_in.role, organization=OrganizationRead(name=organization))
]

return update(db_session=db_session, user=user, user_in=user_in)


Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/static/dispatch/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<v-app>
<div class="app-root">
<router-view />
<router-view :key="$route.path" />
<v-snackbar bottom right :value="updateExists" :timeout="-1" color="info">
An update is available
<template v-slot:action="{ attrs }">
Expand Down
11 changes: 3 additions & 8 deletions src/dispatch/static/dispatch/src/auth/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const getDefaultSelectedState = () => {
email: null,
loading: false,
projects: null,
role: null,
organizations: null,
}
}

Expand All @@ -21,7 +21,7 @@ const state = {
token: null,
email: "",
projects: [],
role: null,
organizations: [],
},
selected: {
...getDefaultSelectedState(),
Expand Down Expand Up @@ -76,8 +76,7 @@ const actions = {
)
})
} else {
return UserApi.update(state.selected.id, state.selected).then(() => {
commit("SET_USER_PROJECTS", state.selected.projects)
return UserApi.update(state.selected.id, state.selected).then((response) => {
dispatch("closeEdit")
dispatch("getAll")
commit(
Expand Down Expand Up @@ -116,7 +115,6 @@ const actions = {
commit("SET_BASIC_LOGIN_LOADING", true)
UserApi.login(payload.email, payload.password).then(function (response) {
commit("SET_USER_LOGIN", response.data.token)
commit("SET_USER_PROJECTS", response.data.projects)
router.push({
name: "IncidentOverview",
})
Expand Down Expand Up @@ -189,9 +187,6 @@ const mutations = {
SET_USER_LOGOUT(state) {
state.currentUser = { loggedIn: false }
},
SET_USER_PROJECTS(state, value) {
state.currentUser.projects = value
},
}

const getters = {
Expand Down
16 changes: 0 additions & 16 deletions src/dispatch/static/dispatch/src/auth/userSettings.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/dispatch/static/dispatch/src/case/Table.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<v-container fluid>
<div v-if="showEditSheet">
<router-view />
<router-view :key="$route.path" />
</div>
<v-row no-gutters>
<new-sheet />
Expand Down
105 changes: 9 additions & 96 deletions src/dispatch/static/dispatch/src/components/AppToolbar.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<template>
<v-app-bar clipped-left clipped-right app flat class="v-bar--underline" color="background0">
<organization-create-edit-dialog />
<!--<v-app-bar-nav-icon @click="handleDrawerToggle" />-->
<router-link :to="{ name: 'IncidentOverview' }" style="text-decoration: none">
<span class="button font-weight-bold">D I S P A T C H</span>
</router-link>
Expand Down Expand Up @@ -59,90 +57,25 @@
</v-list-item>
</v-list>
</v-menu>
<v-menu offset-y>
<template v-slot:activator="{ on }">
<v-btn icon large text v-on="on">
<v-avatar size="30px">
<v-icon> account_circle </v-icon>
</v-avatar>
</v-btn>
</template>
<v-card width="400">
<v-list>
<v-list-item class="px-2">
<v-list-item-avatar>
<v-icon size="30px"> account_circle </v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title class="title" v-text="currentUser().name || currentUser().email">
</v-list-item-title>
<v-list-item-subtitle> {{ currentUser().email }} </v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-tooltip bottom>
<template v-slot:activator="{ on }">
<v-btn icon v-on="on" @click="logout()"><v-icon>logout</v-icon></v-btn>
</template>
<span>Logout</span>
</v-tooltip>
</v-list-item-action>
</v-list-item>
<v-divider></v-divider>
<v-subheader>Organizations</v-subheader>
<v-list-item v-for="(item, i) in organizations" :key="i">
<v-list-item-content>
<v-list-item-title>{{ item.name }}</v-list-item-title>
<v-list-item-subtitle>{{ item.description }}</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-tooltip bottom>
<template v-slot:activator="{ on }">
<v-btn icon v-on="on" @click="showCreateEditDialog(item)"
><v-icon>mdi-pencil-outline</v-icon></v-btn
>
</template>
<span>Edit Organization</span>
</v-tooltip>
</v-list-item-action>
<v-list-item-action>
<v-tooltip bottom>
<template v-slot:activator="{ on }">
<v-btn @click="switchOrganizations(item.slug)" icon v-on="on"
><v-icon>mdi-swap-horizontal</v-icon></v-btn
>
</template>
<span>Switch Organization</span>
</v-tooltip>
</v-list-item-action>
</v-list-item>
</v-list>
<v-list-item @click="showCreateEditDialog()">
<v-list-item-avatar>
<v-icon size="30px">mdi-plus</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>Create a new organization</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-card>
</v-menu>
<organization-menu />
<organization-member-edit-dialog />
<organization-create-edit-dialog />
</v-toolbar-items>
</v-app-bar>
</template>
<script>
import { mapActions, mapMutations, mapState } from "vuex"
import { mapActions, mapMutations } from "vuex"

import Util from "@/util"
import OrganizationApi from "@/organization/api"
import OrganizationCreateEditDialog from "@/organization/CreateEditDialog.vue"

import OrganizationMenu from "@/organization/OrganizationMenu.vue"
import OrganizationMemberEditDialog from "@/organization/OrganizationMemberEditDialog.vue"
import OrganizationCreateEditDialog from "@/organization/OrganizationCreateEditDialog.vue"
export default {
name: "AppToolbar",
data: () => ({
organizations: [],
}),
components: {
OrganizationMenu,
OrganizationCreateEditDialog,
OrganizationMemberEditDialog,
},
computed: {
queryString: {
Expand All @@ -169,26 +102,11 @@ export default {
this.$vuetify.theme.dark = !this.$vuetify.theme.dark
localStorage.setItem("dark_theme", this.$vuetify.theme.dark.toString())
},
switchOrganizations(slug) {
this.$router.push({ params: { organization: slug } })
this.$router.go(this.$router.currentRoute)
},
...mapState("auth", ["currentUser", "userAvatarUrl"]),
...mapActions("auth", ["logout"]),
...mapActions("search", ["setQuery"]),
...mapActions("organization", ["showCreateEditDialog"]),
...mapMutations("search", ["SET_QUERY"]),
},

created() {
this.error = null
this.loading = "error"
let filterOptions = {
itemsPerPage: 50,
sortBy: ["name"],
descending: [false],
}

let theme = localStorage.getItem("dark_theme")
if (theme) {
if (theme === "true") {
Expand All @@ -197,11 +115,6 @@ export default {
this.$vuetify.theme.dark = false
}
}

OrganizationApi.getAll(filterOptions).then((response) => {
this.organizations = response.data.items
this.loading = false
})
},
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<v-main>
<organization-banner />
<div class="page-wrapper">
<router-view />
<router-view :key="$route.path" />
</div>
</v-main>
</v-app>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
<refresh />
<v-main>
<div>
<v-container ma-0 pa-0 fluid>
<router-view />
</v-container>
<v-container ma-0 pa-0 fluid> <router-view :key="$route.path" /> </v-container>
</div>
</v-main>
<!-- Go to top -->
Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/static/dispatch/src/incident/Table.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<v-container fluid>
<div v-if="showEditSheet">
<router-view />
<router-view :key="$route.path" />
</div>
<v-row no-gutters>
<new-sheet />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<template>
<v-dialog v-model="showMemberEditDialog" persistent max-width="600px">
<v-card>
<v-card-title>
<span class="headline">User Settings</span>
</v-card-title>
<v-card-text>
<v-text-field
v-model="selectedMember.email"
disabled
label="Email"
hint="Member's email."
/>
<span class="subtitle-2">Organization Settings</span>
<organization-member-organization-table v-model="selectedMember.organizations" />
<span class="subtitle-2">Project Settings</span>
<organization-member-project-table v-model="selectedMember.projects" />
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn text @click="closeMemberEditDialog()"> Cancel </v-btn>
<v-btn color="info" text @click="updateMember()"> Update </v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>

<script>
import { mapFields } from "vuex-map-fields"
import { mapActions } from "vuex"

import OrganizationMemberProjectTable from "@/organization/OrganizationMemberProjectTable.vue"
import OrganizationMemberOrganizationTable from "@/organization/OrganizationMemberOrganizationTable.vue"

export default {
name: "OrganizationMemberEditDialog",
components: {
OrganizationMemberProjectTable,
OrganizationMemberOrganizationTable,
},

computed: {
...mapFields("organization", ["dialogs.showMemberEditDialog", "selectedMember"]),
},

methods: {
...mapActions("organization", ["updateMember", "closeMemberEditDialog"]),
},
}
</script>
Loading