Skip to content

Commit

Permalink
Merge pull request #77 from TaiBIF/feature-51-check_permission
Browse files Browse the repository at this point in the history
檢查登入人員權限
  • Loading branch information
Chihjen Ko committed Nov 25, 2018
2 parents d94ff1c + 68b1b1a commit 8fcda5e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/pages/index/views/Project.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
{{currentProject.projectTitle}}
</h1>
</div>
<div class="col-3 text-right">
<div
class="col-3 text-right"
v-if="isManager"
>
<!-- TODO: change to project id after API adjust -->
<router-link
to="/info/1/edit"
:to="`/info/${currentProject.projectTitle}/edit`"
class="float-right btn btn-green-border btn-sm"
>
<i class="fa fa-pencil-alt mr-2"></i>
Expand Down Expand Up @@ -394,8 +398,10 @@ import { createNamespacedHelpers } from 'vuex';
import VueHighcharts from 'vue2-highcharts';
import SiteChart from '../components/SiteChart';
import ReportModal from '../components/ReportModal';
import { isRolesManager } from '../../../util/roles.js';
const project = createNamespacedHelpers('project');
const auth = createNamespacedHelpers('auth');
// 設定未選擇/已選擇 Icon
// const Icon = L.icon({
Expand Down Expand Up @@ -660,6 +666,7 @@ export default {
'sites',
'ProjectMarkers',
]),
...auth.mapGetters(['projectRoles']),
reportOptions() {
const tmp = JSON.parse(JSON.stringify(this.cameraLocations || []));
Expand Down Expand Up @@ -687,6 +694,17 @@ export default {
camera: this.currentCamera && this.currentCamera.cameraLocation,
};
},
isManager() {
// TODO: find by projectId after API adjust
const projectRoles = this.projectRoles.find(
projectRole =>
projectRole.projectTitle === this.currentProject.projectTitle,
);
if (!projectRoles) {
return false;
}
return isRolesManager(projectRoles.roles);
},
},
methods: {
...project.mapMutations(['setCurrentProject', 'setSiteStatusTab']),
Expand Down
1 change: 1 addition & 0 deletions src/stores/modules/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getUserInfo } from '../../service/api';
export const getters = {
isLogin: state => !!state.awsToken,
loginUser: state => state.profile,
projectRoles: state => (state.profile && state.profile.project_roles) || [],
};

export const mutations = {
Expand Down
14 changes: 14 additions & 0 deletions src/util/roles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const managerRoles = ['ProjectManager', 'SysAdmin']; // TODO: adjust after define roles for manager

/**
* check project roles include manager or not
* @param {array} roles
* @return {bool}
*/
export const isRolesManager = roles => {
if (!roles || roles.length === 0) {
return false;
}

return roles.some(userRole => managerRoles.includes(userRole));
};

0 comments on commit 8fcda5e

Please sign in to comment.