fix: add tool to make user account from profile view
This commit is contained in:
parent
ddec77c37f
commit
58be7e9d5b
|
@ -1635,28 +1635,30 @@
|
|||
<br />
|
||||
<div id="users-accordion">
|
||||
|
||||
<b-collapse class="panel"
|
||||
v-for="user in users"
|
||||
:key="user.uuid">
|
||||
<${b}-collapse v-for="user in users"
|
||||
:key="user.uuid"
|
||||
class="panel">
|
||||
|
||||
<div slot="trigger"
|
||||
slot-scope="props"
|
||||
class="panel-heading"
|
||||
role="button">
|
||||
<b-icon pack="fas"
|
||||
icon="caret-right">
|
||||
</b-icon>
|
||||
<strong>{{ user.username }}</strong>
|
||||
</div>
|
||||
|
||||
<div class="panel-block">
|
||||
<div style="display: flex; justify-content: space-between; width: 100%;">
|
||||
|
||||
<div>
|
||||
<div class="field-wrapper id">
|
||||
<div class="field-row">
|
||||
<label>Username</label>
|
||||
<div class="field">
|
||||
<div style="flex-grow: 1;">
|
||||
<b-field horizontal label="Username">
|
||||
{{ user.username }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</b-field>
|
||||
<b-field horizontal label="Active">
|
||||
{{ user.active ? "Yes" : "No" }}
|
||||
</b-field>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
@ -1669,13 +1671,66 @@
|
|||
|
||||
</div>
|
||||
</div>
|
||||
</b-collapse>
|
||||
</${b}-collapse>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="!users.length">
|
||||
<div v-if="!users.length"
|
||||
style="display: flex; justify-content: space-between;">
|
||||
|
||||
<p>{{ person.display_name }} does not have a user account.</p>
|
||||
|
||||
% if request.has_perm('users.create'):
|
||||
<b-button type="primary"
|
||||
icon-pack="fas"
|
||||
icon-left="plus"
|
||||
@click="createUserInit()">
|
||||
Create User
|
||||
</b-button>
|
||||
|
||||
<${b}-modal has-modal-card
|
||||
% if request.use_oruga:
|
||||
v-model:active="createUserShowDialog"
|
||||
% else:
|
||||
:active.sync="createUserShowDialog"
|
||||
% endif
|
||||
>
|
||||
<div class="modal-card">
|
||||
|
||||
<header class="modal-card-head">
|
||||
<p class="modal-card-title">Create User</p>
|
||||
</header>
|
||||
|
||||
<section class="modal-card-body">
|
||||
<b-field label="Person">
|
||||
<span>{{ person.display_name }}</span>
|
||||
</b-field>
|
||||
<b-field label="Username">
|
||||
<b-input v-model="createUserUsername"
|
||||
ref="username" />
|
||||
</b-field>
|
||||
<b-field label="Active">
|
||||
<b-checkbox v-model="createUserActive" />
|
||||
</b-field>
|
||||
</section>
|
||||
|
||||
<footer class="modal-card-foot">
|
||||
<b-button @click="createUserShowDialog = false">
|
||||
Cancel
|
||||
</b-button>
|
||||
<b-button type="is-primary"
|
||||
@click="createUserSave()"
|
||||
:disabled="createUserSaveDisabled"
|
||||
icon-pack="fas"
|
||||
icon-left="save">
|
||||
{{ createUserSaving ? "Working, please wait..." : "Save" }}
|
||||
</b-button>
|
||||
</footer>
|
||||
</div>
|
||||
</${b}-modal>
|
||||
% endif
|
||||
</div>
|
||||
|
||||
% if request.use_oruga:
|
||||
<o-loading v-model:active="refreshingTab" :full-page="false"></o-loading>
|
||||
% else:
|
||||
|
@ -2730,6 +2785,13 @@
|
|||
let UserTabData = {
|
||||
refreshTabURL: '${url('people.profile_tab_user', uuid=person.uuid)}',
|
||||
users: [],
|
||||
|
||||
% if request.has_perm('users.create'):
|
||||
createUserShowDialog: false,
|
||||
createUserUsername: null,
|
||||
createUserActive: false,
|
||||
createUserSaving: false,
|
||||
% endif
|
||||
}
|
||||
|
||||
let UserTab = {
|
||||
|
@ -2738,12 +2800,62 @@
|
|||
props: {
|
||||
person: Object,
|
||||
},
|
||||
computed: {},
|
||||
|
||||
computed: {
|
||||
|
||||
% if request.has_perm('users.create'):
|
||||
|
||||
createUserSaveDisabled() {
|
||||
if (this.createUserSaving) {
|
||||
return true
|
||||
}
|
||||
if (!this.createUserUsername) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
},
|
||||
|
||||
% endif
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
refreshTabSuccess(response) {
|
||||
this.users = response.data.users
|
||||
this.createUserSuggestedUsername = response.data.suggested_username
|
||||
},
|
||||
|
||||
% if request.has_perm('users.create'):
|
||||
|
||||
createUserInit() {
|
||||
this.createUserUsername = this.createUserSuggestedUsername
|
||||
this.createUserActive = true
|
||||
this.createUserShowDialog = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs.username.focus()
|
||||
})
|
||||
},
|
||||
|
||||
createUserSave() {
|
||||
this.createUserSaving = true
|
||||
|
||||
let url = '${master.get_action_url('profile_make_user', instance)}'
|
||||
let params = {
|
||||
username: this.createUserUsername,
|
||||
active: this.createUserActive,
|
||||
}
|
||||
|
||||
this.simplePOST(url, params, response => {
|
||||
this.$emit('profile-changed', response.data)
|
||||
this.createUserSaving = false
|
||||
this.createUserShowDialog = false
|
||||
this.refreshTab()
|
||||
}, response => {
|
||||
this.createUserSaving = false
|
||||
})
|
||||
},
|
||||
|
||||
% endif
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -1280,11 +1280,40 @@ class PersonView(MasterView):
|
|||
"""
|
||||
Fetch user tab data for profile view.
|
||||
"""
|
||||
app = self.get_rattail_app()
|
||||
auth = app.get_auth_handler()
|
||||
person = self.get_instance()
|
||||
return {
|
||||
context = {
|
||||
'users': self.get_context_users(person),
|
||||
}
|
||||
|
||||
if not context['users']:
|
||||
context['suggested_username'] = auth.generate_unique_username(self.Session(),
|
||||
person=person)
|
||||
|
||||
return context
|
||||
|
||||
def profile_make_user(self):
|
||||
"""
|
||||
Create a new user account, presumably from the profile view.
|
||||
"""
|
||||
app = self.get_rattail_app()
|
||||
model = self.model
|
||||
auth = app.get_auth_handler()
|
||||
|
||||
person = self.get_instance()
|
||||
if person.users:
|
||||
return {'error': f"This person already has {len(person.users)} user accounts."}
|
||||
|
||||
data = self.request.json_body
|
||||
user = auth.make_user(session=self.Session(),
|
||||
person=person,
|
||||
username=data['username'],
|
||||
active=data['active'])
|
||||
|
||||
self.Session.flush()
|
||||
return self.profile_changed_response(person)
|
||||
|
||||
def profile_revisions_grid(self, person):
|
||||
route_prefix = self.get_route_prefix()
|
||||
factory = self.get_grid_factory()
|
||||
|
@ -1787,6 +1816,15 @@ class PersonView(MasterView):
|
|||
route_name=f'{route_prefix}.profile_tab_user',
|
||||
renderer='json')
|
||||
|
||||
# profile - make user
|
||||
config.add_route(f'{route_prefix}.profile_make_user',
|
||||
f'{instance_url_prefix}/make-user',
|
||||
request_method='POST')
|
||||
config.add_view(cls, attr='profile_make_user',
|
||||
route_name=f'{route_prefix}.profile_make_user',
|
||||
permission='users.create',
|
||||
renderer='json')
|
||||
|
||||
# profile - revisions data
|
||||
config.add_tailbone_permission('people_profile',
|
||||
'people_profile.view_versions',
|
||||
|
|
Loading…
Reference in a new issue