-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add permissions management * hide required permission by default * update permission description * update strings Co-authored-by: Brendan Early <[email protected]>
- Loading branch information
1 parent
05dbda0
commit c3909f4
Showing
12 changed files
with
503 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
@import "ui"; | ||
|
||
[v-cloak] { | ||
display: none; | ||
} | ||
|
||
* { | ||
font-family: arial, "Microsoft YaHei"; | ||
} | ||
|
||
p { | ||
font-size: 16px; | ||
} | ||
|
||
#permissions { | ||
width: 900px; | ||
position: relative; | ||
margin: 0 auto; | ||
} | ||
|
||
h2 { | ||
margin-top: 3em; | ||
} | ||
|
||
button { | ||
display: inline-grid; | ||
padding: 10px 20px; | ||
border: #ccc 1px solid; | ||
background: white; | ||
border-radius: 2px; | ||
position: relative; | ||
text-align: center; | ||
align-items: center; | ||
font-size: 16px; | ||
color: gray; | ||
cursor: pointer; | ||
outline: none; | ||
margin-left: 0px !important; | ||
|
||
&:not(:disabled):hover { | ||
color: black; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<template> | ||
<div id="permissions" class="theme-normal"> | ||
<h1>Permissions</h1> | ||
<div> | ||
<input | ||
type="checkbox" | ||
id="showRequiredPermission" | ||
v-model="showAllPermissions" | ||
/> | ||
<label for="showRequiredPermission">{{ | ||
i18n.permission_show_required_permissions | ||
}}</label> | ||
</div> | ||
<div v-for="permission in permissions" :key="permission.id"> | ||
<h2>{{ permission.id }}</h2> | ||
<p>{{ permission.description }}</p> | ||
<p v-if="!permission.revocable">{{ i18n.permission_required }}</p> | ||
<button | ||
:disabled="!permission.revocable" | ||
v-if="permission.revocable" | ||
v-on:click="revoke(permission.id)" | ||
> | ||
{{ i18n.permission_revoke }} | ||
</button> | ||
</div> | ||
</div> | ||
</template> | ||
<script lang="ts"> | ||
import Vue from "vue"; | ||
import { Permission } from "../models/permission"; | ||
export default Vue.extend({ | ||
computed: { | ||
permissions: function () { | ||
return this.$store.state.permissions.permissions.filter( | ||
(permission: Permission) => { | ||
return this.showAllPermissions || permission.revocable; | ||
} | ||
); | ||
}, | ||
}, | ||
data: function () { | ||
return { | ||
showAllPermissions: false, | ||
}; | ||
}, | ||
methods: { | ||
revoke(permissionId: string) { | ||
this.$store.commit("permissions/revokePermission", permissionId); | ||
}, | ||
}, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
interface ValidationResult { | ||
valid: boolean; | ||
message?: string; | ||
} | ||
|
||
interface PermissionInterface { | ||
id: string; | ||
description: string; | ||
revocable: boolean; | ||
validation?: Array<() => ValidationResult>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export class Permission implements PermissionInterface { | ||
id: string; | ||
description: string; | ||
revocable: boolean; | ||
validation?: Array<() => ValidationResult>; | ||
|
||
constructor(permission: PermissionInterface) { | ||
this.id = permission.id; | ||
this.description = permission.description; | ||
this.revocable = permission.revocable; | ||
this.validation = permission.validation; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Vue | ||
import Vue from "vue"; | ||
import Vuex from "vuex"; | ||
|
||
// Components | ||
import PermissionsView from "./components/Permissions.vue"; | ||
import CommonComponents from "./components/common/index"; | ||
|
||
// Other | ||
import { loadI18nMessages } from "./store/i18n"; | ||
import { Permissions } from "./store/Permissions"; | ||
|
||
async function init() { | ||
// i18n | ||
Vue.prototype.i18n = await loadI18nMessages(); | ||
|
||
// Load modules | ||
Vue.use(Vuex); | ||
|
||
// Load common components globally | ||
for (const component of CommonComponents) { | ||
Vue.component(component.name, component.component); | ||
} | ||
|
||
// State | ||
const store = new Vuex.Store({ | ||
modules: { | ||
permissions: await new Permissions().getModule(), | ||
}, | ||
}); | ||
|
||
const instance = new Vue({ | ||
render: (h) => h(PermissionsView), | ||
store, | ||
}).$mount("#permissions"); | ||
|
||
// Set title | ||
try { | ||
document.title = instance.i18n.extName; | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
|
||
init(); |
Oops, something went wrong.
_locales/en/messages.json