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

feat:User CRUD #35

Merged
merged 9 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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: 2 additions & 1 deletion src/components/IndicatorCell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<v-icon class="mx-1" color="red" v-on="on">{{ mdiEngineOff,
}}</v-icon>
</template>
<span>Disabled</span>
<span>{{ disableLabel }}</span>
</v-tooltip>

<v-tooltip v-if="value.is_hidden === true" bottom>
Expand All @@ -27,6 +27,7 @@
<script>
export default {
props: {
disableLabel: { default: 'Disabled', type: String },
hideDescription: { default: false, type: Boolean },
value: { type: Object, required: true }
}
Expand Down
5 changes: 3 additions & 2 deletions src/components/MainNavigationDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,14 @@ export default {
]
},
{
header: 'Admin section',
header: 'Admin',
items: [
{
can: ['read', 'users'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

admin section will still be shown to a standard user in this case.
I believe admin section should be shown to only manager and sys admin
Related to #43

Copy link
Collaborator

Choose a reason for hiding this comment

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

making a note that we also want this nav section to be hidden when you "drill down" into an Org. And we want to change the name Admin Section => Admin

Copy link
Collaborator

Choose a reason for hiding this comment

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

admin section will still be shown to standard users (in addition to managers and admins) but perhaps that is our intent

Copy link
Collaborator

Choose a reason for hiding this comment

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

we discussed today, @ergjustin will make this can -> canCreate

icon: mdiAccountGroup,
title: 'Users',
to: '/users'
to: '/users',
org: false
}
]
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/UserDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
chips
deletable-chips
dense
label="Roles"
label="Role"
hide-details
small-chips
variant="solo"
Expand Down Expand Up @@ -127,9 +127,9 @@ export default {
},

props: {
create: { default: false, type: Boolean },
editing: { default: false, type: Boolean },
value: { type: Object, required: true },
create: { default: false, type: Boolean }
value: { type: Object, required: true }
},

computed: {
Expand Down
37 changes: 22 additions & 15 deletions src/components/UserPasswordEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
<v-card-title class="headline"> Change password </v-card-title>

<v-card-text>
<ValidationProvider
v-slot="{ errors }"
name="current password"
rules="required|min:10|max:100"
>
<v-text-field
v-model="current_password"
:error-messages="errors"
label="Current password"
required
type="password"
></v-text-field>
</ValidationProvider>
<template v-if="currentPasswordRequired">
<ValidationProvider
v-slot="{ errors }"
name="current password"
rules="required|min:10|max:100"
>
<v-text-field
v-model="current_password"
:error-messages="errors"
label="Current password"
required
type="password"
></v-text-field>
</ValidationProvider>
</template>

<ValidationProvider
v-slot="{ errors }"
Expand Down Expand Up @@ -75,6 +77,8 @@ export default {
},

props: {
currentPasswordRequired: { default: true, type: Boolean },
editStatus: { default: false, type: Boolean },
user: { default: null, type: Object }
},

Expand Down Expand Up @@ -105,13 +109,16 @@ export default {

return this.patch([this.id, { $set }, {}])
.then(() =>
this.$bus.$emit('status', {
this.$bus.$emit(this.editStatus ? 'edit-status' : 'status', {
type: 'success',
message: 'Password changed.' // TODO: Localize
})
)
.catch(({ message }) =>
this.$bus.$emit('status', { type: 'error', message })
this.$bus.$emit(this.editStatus ? 'edit-status' : 'status', {
type: 'error',
message
})
)
}
}
Expand Down
17 changes: 13 additions & 4 deletions src/components/UsersSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
filled
flat
hide-details
multiple
small-chips
></v-select>
</v-col>
Expand Down Expand Up @@ -86,7 +87,7 @@
</template>

<template #item.indicators="{ item }">
<indicator-cell :value="item" />
<indicator-cell disable-label="Deactivated" :value="item" />
</template>

<template #item.icons="{ item }">
Expand Down Expand Up @@ -149,7 +150,7 @@ export default {
}
],

optionItems: ['Deactivated'],
optionItems: ['Active', 'Deactivated'],
rolesOption: ['manager', 'user'],

queryUserIds: [],
Expand Down Expand Up @@ -182,8 +183,16 @@ export default {

const ands = []

if (selectedOptions && selectedOptions.includes('Deactivated')) {
ands.push({ is_enabled: false })
if (
selectedOptions &&
selectedOptions.length &&
this.optionItems.length !== selectedOptions.length
) {
ands.push({
is_enabled:
selectedOptions.includes('Active') &&
!selectedOptions.includes('Deactivated')
})
}

if (selectedRoles && selectedRoles.length) {
Expand Down
11 changes: 9 additions & 2 deletions src/layouts/editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

<v-toolbar-items>
<v-btn
:disabled="editorDirty < 1"
:disabled="editorDirty < 1 || isLoading"
text
:loading="isLoading"
@click="$bus.$emit('editor-save')"
>Save</v-btn
>
Expand Down Expand Up @@ -98,7 +99,13 @@ export default {
}),

computed: {
...mapState('ux', ['editing', 'editorColor', 'editorDirty', 'editorTitle'])
...mapState('ux', [
'editing',
'editorColor',
'editorDirty',
'editorTitle',
'isLoading'
])
},

watch: {
Expand Down
21 changes: 20 additions & 1 deletion src/pages/users/_userId/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
</v-col>
</v-row>

<v-row v-if="!editing && $canPatch('users', instance)">
<v-col>
<user-password-edit
:current-password-required="
$cannotPatch('users', { _id: instance._id })
"
:edit-status="!editing"
:user="instance"
/>
</v-col>
</v-row>

<v-btn
v-show="!editing && $canPatch('users', instance)"
color="primary"
Expand All @@ -37,9 +49,11 @@ import _merge from 'lodash/merge'
import _omit from 'lodash/omit'
import { defaultUser, patchData } from '@/lib/edit'
import UserDetail from '@/components/UserDetail'
import UserPasswordEdit from '@/components/UserPasswordEdit'
export default {
components: {
UserDetail,
UserPasswordEdit,
ValidationObserver
},

Expand Down Expand Up @@ -100,7 +114,8 @@ export default {
incEditorDirty: 'ux/incEditorDirty',
setEditorColor: 'ux/setEditorColor',
setEditorDirty: 'ux/setEditorDirty',
setEditorTitle: 'ux/setEditorTitle'
setEditorTitle: 'ux/setEditorTitle',
setIsLoading: 'ux/setIsLoading'
}),

edit() {
Expand Down Expand Up @@ -132,6 +147,8 @@ export default {
roles: [instance.roles]
})

this.setIsLoading(true)

try {
// HACK: Ensure that we have a fresh model afterwards
this.$store.commit('users/removeItem', instance._id)
Expand All @@ -153,6 +170,8 @@ export default {
this.$store.commit('users/removeItem', instance._id)

await this.fetchUsers({ query: { _id: instance._id } })
} finally {
this.setIsLoading(false)
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/pages/users/create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export default {
incEditorDirty: 'ux/incEditorDirty',
setEditorColor: 'ux/setEditorColor',
setEditorDirty: 'ux/setEditorDirty',
setEditorTitle: 'ux/setEditorTitle'
setEditorTitle: 'ux/setEditorTitle',
setIsLoading: 'ux/setIsLoading'
}),

cancel() {
Expand Down Expand Up @@ -128,6 +129,8 @@ export default {
type: 'error',
message: err.message
})
} finally {
this.setIsLoading(false)
}
},

Expand All @@ -136,6 +139,8 @@ export default {

const { instance } = this

this.setIsLoading(true)

try {
const person = await this.fetchPersons({
query: {
Expand All @@ -158,6 +163,7 @@ export default {
type: 'error',
message: err.message
})
this.setIsLoading(false)
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/store/ux.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export const state = () => ({
editing: false,
editorColor: 'primary',
editorDirty: 0,
editorTitle: ''
editorTitle: '',
isLoading: false
})

export const actions = {}
Expand Down Expand Up @@ -43,5 +44,8 @@ export const mutations = {
},
setEditorTitle(state, value) {
state.editorTitle = value
},
setIsLoading(state, value) {
state.isLoading = value
}
}