Browse Source

add support for admin managing account policies and ssh keys

pull/1/head
Jonathan Cobb 4 years ago
parent
commit
7b0bc74bd5
3 changed files with 91 additions and 33 deletions
  1. +38
    -16
      src/account/profile/PolicyPage.vue
  2. +5
    -2
      src/account/profile/ProfilePage.vue
  3. +48
    -15
      src/account/profile/SshKeysPage.vue

+ 38
- 16
src/account/profile/PolicyPage.vue View File

@@ -7,7 +7,7 @@
<div v-if="errors.has('request')" class="invalid-feedback d-block">{{ errors.first('request') }}</div>
</div>

<h2>{{messages.form_title_account_policy}}</h2>
<h2>{{messages.form_title_account_policy}}<span v-if="this.me === false"> - {{this.userId}}</span></h2>
<form @submit.prevent="updatePolicy">
<hr/>
<div class="form-group">
@@ -337,6 +337,7 @@

<script>
import { mapState, mapActions, mapGetters } from 'vuex';
import { util } from '../../_helpers';

// convenience methods
import { isAuthenticator, isNotAuthenticator } from '../../_store/users.module';
@@ -366,6 +367,10 @@
export default {
data() {
return {
me: null,
userId: null,
linkPrefix: null,
currentUser: util.currentUser(),
submitted: false,
deletionPolicy: '',
accountOperationTimeout: '',
@@ -384,15 +389,12 @@
}
},
computed: {
...mapState('account', {
currentUser: state => state.user
}),
...mapState('account', ['actionStatus']),
...mapState('system', [
'messages', 'accountDeletionOptions', 'timeDurationOptions', 'timeDurationOptionsReversed',
'contactTypes', 'detectedLocale', 'countries'
]),
...mapState('users', ['policy', 'contact', 'authenticator']),
...mapState('users', ['user', 'policy', 'contact', 'authenticator']),
hasAuthenticator() {
for (let i=0; i<this.contacts.length; i++) {
if (isAuthenticator(this.contacts[i])) return true;
@@ -433,7 +435,7 @@
this.errors.clear();
this.submitted = true;
this.updatePolicyByUserId({
userId: this.currentUser.uuid,
userId: this.userId,
policy: {
deletionPolicy: this.deletionPolicy,
accountOperationTimeout: this.messages.durationToMillis(this.accountOperationTimeout, this.accountOperationTimeoutUnits),
@@ -453,7 +455,7 @@
this.errors.clear();
// console.log('addContact: adding: '+JSON.stringify(contactToAdd));
this.addPolicyContactByUserId({
userId: this.currentUser.uuid,
userId: this.userId,
contact: contactToAdd,
messages: this.messages,
errors: this.errors
@@ -462,7 +464,7 @@
removeContact(uuid) {
this.errors.clear();
this.removePolicyContactByUserId({
userId: this.currentUser.uuid,
userId: this.userId,
contactUuid: uuid,
messages: this.messages,
errors: this.errors
@@ -484,7 +486,7 @@
const c = this.prepContact(contact);
// console.log('contactFlag: update: '+JSON.stringify(c));
this.addPolicyContactByUserId({
userId: this.currentUser.uuid,
userId: this.userId,
contact: c,
messages: this.messages,
errors: this.errors
@@ -510,7 +512,7 @@
const c = this.prepContact(contact);
c.authFactor = factor;
this.addPolicyContactByUserId({
userId: this.currentUser.uuid,
userId: this.userId,
contact: c,
messages: this.messages,
errors: this.errors
@@ -524,7 +526,7 @@
resendVerification(contact) {
this.errors.clear();
this.resendVerificationCode({
userId: this.currentUser.uuid,
userId: this.userId,
contact: contact,
messages: this.messages,
errors: this.errors
@@ -565,7 +567,7 @@
if (isAuthenticator(type)) {
// console.log('submitVerification: sending authenticator code: '+code);
this.sendAuthenticatorCode({
userId: this.currentUser.uuid,
userId: this.userId,
code: code,
authOnly: null,
verifyOnly: true,
@@ -574,7 +576,7 @@
});
} else {
this.approveAction({
userId: this.currentUser.uuid,
userId: this.userId,
code: code,
messages: this.messages,
errors: this.errors
@@ -609,13 +611,13 @@
// console.log('watch.contact: received: '+JSON.stringify(c));
if (typeof c.error === 'undefined' || c.error === null) {
// force reload policy, refreshes contacts
this.getPolicyByUserId({userId: this.currentUser.uuid, messages: this.messages, errors: this.errors});
this.getPolicyByUserId({userId: this.userId, messages: this.messages, errors: this.errors});
}
},
actionStatus (status) {
// console.log('watch.actionStatus: received: '+JSON.stringify(status));
if (status.success) {
this.getPolicyByUserId({userId: this.currentUser.uuid, messages: this.messages, errors: this.errors});
this.getPolicyByUserId({userId: this.userId, messages: this.messages, errors: this.errors});
}
},
authenticator (auth) {
@@ -642,7 +644,27 @@
}
},
created () {
this.getPolicyByUserId({userId: this.currentUser.uuid, messages: this.messages, errors: this.errors});
this.me = this.$route.path.startsWith('/me/');
if (this.me) {
this.userId = this.currentUser.uuid;
this.linkPrefix = '/me';
this.getPolicyByUserId({userId: this.currentUser.uuid, messages: this.messages, errors: this.errors});

} else if (this.currentUser.admin !== true) {
console.warn('PolicyPage.created: /me requested but no currentUser, sending to home page');
this.$router.push('/');
return;

} else if (typeof this.$route.params.id === 'undefined' || this.$route.params.id === null) {
console.warn('PolicyPage.created: no id param found, sending to accounts page');
this.$router.push('/admin/accounts');
return;

} else {
this.userId = this.$route.params.id;
this.linkPrefix = '/admin/accounts/' + this.userId;
this.getPolicyByUserId({userId: this.userId, messages: this.messages, errors: this.errors});
}
// console.log('PolicyPage.created: $route.params='+JSON.stringify(this.$route.query));
if (this.$route.query.action) {
this.inboundAction = {


+ 5
- 2
src/account/profile/ProfilePage.vue View File

@@ -144,8 +144,10 @@
this.linkPrefix = '/me';
if (this.currentUser === null) {
this.admin = false;
console.warn('/me requested but no currentUser, sending to home page');
console.warn('ProfilePage.created: /me requested but no currentUser, sending to home page');
this.$router.push('/');
return;

} else {
this.admin = this.currentUser.admin === true;
this.getUserById({
@@ -156,8 +158,9 @@
}

} else if (this.currentUser.admin !== true) {
console.log('ProfilePage.created: not admin and path not /me, sending to /me ...');
console.warn('ProfilePage.created: not admin and path not /me, sending to /me ...');
this.$router.push('/me');
return;

} else {
this.admin = this.currentUser.admin === true;


+ 48
- 15
src/account/profile/SshKeysPage.vue View File

@@ -1,6 +1,6 @@
<template>
<div>
<h4>{{messages.form_title_ssh_keys}}</h4>
<h4>{{messages.form_title_ssh_keys}}<span v-if="this.me === false"> - {{this.userId}}</span></h4>
<table border="1">
<thead>
<tr>
@@ -71,15 +71,18 @@
</template>

<script>
import { mapState, mapActions, mapGetters } from 'vuex'
import { util } from '../../_helpers'
import { Settings } from 'luxon'
import { mapState, mapActions, mapGetters } from 'vuex';
import { util } from '../../_helpers';
import { Settings } from 'luxon';

export default {
data() {
return {
me: null,
userId: null,
linkPrefix: null,
submitted: false,
user: util.currentUser(),
currentUser: util.currentUser(),
name: null,
expiration: null,
sshPublicKey: null,
@@ -90,7 +93,7 @@
},
computed: {
...mapState('system', ['messages', 'detectedTimezone', 'detectedLocale']),
...mapState('users', ['sshKeys']),
...mapState('users', ['user', 'sshKeys']),
newKeyValid () {
return (this.name !== null && this.name !== '')
&& (this.sshPublicKey !== null && this.sshPublicKey !== '' && this.sshPublicKey.startsWith('ssh-rsa '));
@@ -107,7 +110,7 @@
this.errors.clear();
this.submitted = true;
this.addSshKeyByUserId({
userId: this.user.uuid,
userId: this.userId,
sshKey: {
name: this.name,
sshPublicKey: this.sshPublicKey,
@@ -120,7 +123,7 @@
},
removeSshKey (keyId) {
this.removeSshKeyByUserId({
userId: this.user.uuid,
userId: this.userId,
sshKeyId: keyId,
messages: this.messages,
errors: this.errors
@@ -143,15 +146,45 @@
} else {
this.timezone = this.detectedTimezone.timeZoneId;
}
const user = util.currentUser();
if (util.userHasLocale(user)) {
Settings.defaultLocale = util.jsLocale(this.user, null);
} else if (this.detectedLocale === null) {
this.detectLocale();

this.me = this.$route.path.startsWith('/me/');
if (this.me) {
this.linkPrefix = '/me';
if (this.currentUser === null) {
this.admin = false;
console.warn('SshKeysPage.created: /me requested but no currentUser, sending to home page');
this.$router.push('/');
return;

} else {
this.admin = this.currentUser.admin === true;
this.userId = this.currentUser.uuid;
}

} else if (this.currentUser.admin !== true) {
console.warn('SshKeysPage.created: not admin and path not /me, sending to /me ...');
this.$router.push('/me');
return;

} else if (typeof this.$route.params.id === 'undefined' || this.$route.params.id === null) {
console.warn('SshKeysPage.created: no id param found, sending to accounts page');
this.$router.push('/admin/accounts');
return;

} else {
Settings.defaultLocale = util.jsLocale(null, this.detectedLocale);
this.userId = this.$route.params.id;
this.linkPrefix = '/admin/accounts/' + this.userId;
}
this.listSshKeysByUserId({userId: user.uuid, messages: this.messages, errors: this.errors});

// const user = util.currentUser();
// if (util.userHasLocale(user)) {
// Settings.defaultLocale = util.jsLocale(this.user, null);
// } else if (this.detectedLocale === null) {
// this.detectLocale();
// } else {
// Settings.defaultLocale = util.jsLocale(null, this.detectedLocale);
// }
this.listSshKeysByUserId({userId: this.userId, messages: this.messages, errors: this.errors});
}
};
</script>

Loading…
Cancel
Save