2023-12-05 03:59:16 +08:00
|
|
|
<template>
|
|
|
|
<div>
|
2024-01-29 22:19:25 +08:00
|
|
|
<div v-if="roles.length > 0 && visible" class="p-2 flex items-center gap-2 border-solid border-0 border-b border-b-sn-sleepy-grey">
|
|
|
|
<div>
|
|
|
|
<img src="/images/icon/team.png" class="rounded-full w-8 h-8">
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{{ i18n.t('access_permissions.everyone_else', { team_name: params.object.team }) }}
|
|
|
|
</div>
|
|
|
|
<i class="sn-icon sn-icon-info"
|
|
|
|
:title='this.autoAssignedUsers.map((ua) => ua.attributes.user.name).join("\u000d")'></i>
|
|
|
|
<MenuDropdown
|
|
|
|
v-if="params.object.top_level_assignable && params.object.urls.update_access"
|
|
|
|
class="ml-auto"
|
|
|
|
:listItems="rolesFromatted"
|
|
|
|
:btnText="this.roles.find((role) => role[0] == default_role)[1]"
|
|
|
|
:position="'right'"
|
|
|
|
:caret="true"
|
|
|
|
@setRole="(...args) => this.changeDefaultRole(...args)"
|
|
|
|
@removeRole="() => this.changeDefaultRole()"
|
|
|
|
></MenuDropdown>
|
|
|
|
<div class="ml-auto btn btn-light pointer-events-none" v-else>
|
|
|
|
{{ this.roles.find((role) => role[0] == default_role)[1] }}
|
|
|
|
<div class="h-6 w-6"></div>
|
|
|
|
</div>
|
2023-12-05 03:59:16 +08:00
|
|
|
</div>
|
2024-01-29 22:19:25 +08:00
|
|
|
<perfect-scrollbar class="h-[50vh] relative">
|
|
|
|
<div v-for="userAssignment in manuallyAssignedUsers"
|
|
|
|
:key="userAssignment.id"
|
|
|
|
class="p-2 flex items-center gap-2">
|
|
|
|
<div>
|
|
|
|
<img :src="userAssignment.attributes.user.avatar_url" class="rounded-full w-8 h-8">
|
2023-12-05 03:59:16 +08:00
|
|
|
</div>
|
2024-01-29 22:19:25 +08:00
|
|
|
<div>
|
|
|
|
<div>{{ userAssignment.attributes.user.name }}</div>
|
|
|
|
<div class="text-xs text-sn-grey">{{ userAssignment.attributes.inherit_message }}</div>
|
|
|
|
</div>
|
|
|
|
<MenuDropdown
|
|
|
|
v-if="!userAssignment.attributes.last_owner && params.object.urls.update_access"
|
|
|
|
class="ml-auto"
|
|
|
|
:listItems="rolesFromatted"
|
|
|
|
:btnText="userAssignment.attributes.user_role.name"
|
|
|
|
:position="'right'"
|
|
|
|
:caret="true"
|
|
|
|
@setRole="(...args) => this.changeRole(userAssignment.attributes.user.id, ...args)"
|
|
|
|
@removeRole="() => this.removeRole(userAssignment.attributes.user.id)"
|
|
|
|
></MenuDropdown>
|
|
|
|
<div class="ml-auto btn btn-light pointer-events-none" v-else>
|
|
|
|
{{ userAssignment.attributes.user_role.name }}
|
|
|
|
<div class="h-6 w-6"></div>
|
2023-12-05 03:59:16 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-01-29 22:19:25 +08:00
|
|
|
</perfect-scrollbar>
|
2023-12-05 03:59:16 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-12-11 22:41:03 +08:00
|
|
|
/* global HelperModule */
|
|
|
|
|
|
|
|
import MenuDropdown from '../menu_dropdown.vue';
|
2023-12-05 03:59:16 +08:00
|
|
|
import axios from '../../../packs/custom_axios.js';
|
|
|
|
|
|
|
|
export default {
|
2024-01-29 22:19:25 +08:00
|
|
|
emits: ['modified', 'usersReloaded', 'changeVisibility'],
|
2023-12-05 03:59:16 +08:00
|
|
|
props: {
|
|
|
|
params: {
|
|
|
|
type: Object,
|
2023-12-12 19:17:38 +08:00
|
|
|
required: true
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
visible: {
|
2023-12-12 19:17:38 +08:00
|
|
|
type: Boolean
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
default_role: {
|
2023-12-12 19:17:38 +08:00
|
|
|
type: Number
|
2024-01-29 22:19:25 +08:00
|
|
|
},
|
|
|
|
reloadUsers: {
|
|
|
|
type: Boolean
|
2023-12-12 19:17:38 +08:00
|
|
|
}
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.getAssignedUsers();
|
|
|
|
this.getRoles();
|
|
|
|
},
|
2024-01-29 22:19:25 +08:00
|
|
|
watch: {
|
|
|
|
reloadUsers() {
|
|
|
|
if (this.reloadUsers) {
|
|
|
|
this.getAssignedUsers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-12-05 03:59:16 +08:00
|
|
|
components: {
|
2023-12-12 19:17:38 +08:00
|
|
|
MenuDropdown
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
rolesFromatted() {
|
2023-12-11 22:41:03 +08:00
|
|
|
let roles = [];
|
|
|
|
|
|
|
|
if (!this.params.object.top_level_assignable) {
|
|
|
|
roles.push({
|
|
|
|
emit: 'setRole',
|
|
|
|
text: this.i18n.t('access_permissions.reset'),
|
2023-12-12 19:17:38 +08:00
|
|
|
params: 'reset'
|
2023-12-11 22:41:03 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
roles = roles.concat(this.roles.map((role) => (
|
|
|
|
{
|
2023-12-05 03:59:16 +08:00
|
|
|
emit: 'setRole',
|
|
|
|
text: role[1],
|
2023-12-12 19:17:38 +08:00
|
|
|
params: role[0]
|
2023-12-05 03:59:16 +08:00
|
|
|
}
|
2023-12-11 22:41:03 +08:00
|
|
|
)));
|
2023-12-05 03:59:16 +08:00
|
|
|
|
2023-12-11 22:41:03 +08:00
|
|
|
if (this.params.object.top_level_assignable) {
|
|
|
|
roles.push({
|
|
|
|
dividerBefore: true,
|
|
|
|
emit: 'removeRole',
|
2023-12-12 19:17:38 +08:00
|
|
|
text: this.i18n.t('access_permissions.remove_access')
|
2023-12-11 22:41:03 +08:00
|
|
|
});
|
|
|
|
}
|
2023-12-05 03:59:16 +08:00
|
|
|
|
2023-12-11 22:41:03 +08:00
|
|
|
return roles;
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
manuallyAssignedUsers() {
|
2023-12-11 22:41:03 +08:00
|
|
|
return this.assignedUsers.filter((user) => (
|
|
|
|
user.attributes.assigned === 'manually'
|
|
|
|
));
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
autoAssignedUsers() {
|
2023-12-11 22:41:03 +08:00
|
|
|
return this.assignedUsers.filter((user) => (
|
|
|
|
user.attributes.assigned === 'automatically'
|
|
|
|
));
|
2023-12-12 19:17:38 +08:00
|
|
|
}
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
assignedUsers: [],
|
2023-12-12 19:17:38 +08:00
|
|
|
roles: []
|
2023-12-05 03:59:16 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getAssignedUsers() {
|
|
|
|
axios.get(this.params.object.urls.show_access)
|
|
|
|
.then((response) => {
|
|
|
|
this.assignedUsers = response.data.data;
|
2024-01-29 22:19:25 +08:00
|
|
|
this.$emit('usersReloaded');
|
2023-12-11 22:41:03 +08:00
|
|
|
});
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
getRoles() {
|
|
|
|
axios.get(this.params.roles_path)
|
|
|
|
.then((response) => {
|
|
|
|
this.roles = response.data.data;
|
2023-12-11 22:41:03 +08:00
|
|
|
});
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
2023-12-11 22:41:03 +08:00
|
|
|
changeRole(id, roleId) {
|
|
|
|
axios.put(this.params.object.urls.update_access, {
|
2023-12-05 03:59:16 +08:00
|
|
|
user_assignment: {
|
|
|
|
user_id: id,
|
2023-12-12 19:17:38 +08:00
|
|
|
user_role_id: roleId
|
|
|
|
}
|
2023-12-11 22:41:03 +08:00
|
|
|
}).then(() => {
|
2023-12-05 03:59:16 +08:00
|
|
|
this.$emit('modified');
|
|
|
|
this.getAssignedUsers();
|
2023-12-11 22:41:03 +08:00
|
|
|
});
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
removeRole(id) {
|
2023-12-11 22:41:03 +08:00
|
|
|
axios.delete(this.params.object.urls.update_access, {
|
2023-12-05 03:59:16 +08:00
|
|
|
data: {
|
2023-12-12 19:17:38 +08:00
|
|
|
user_id: id
|
|
|
|
}
|
2023-12-05 03:59:16 +08:00
|
|
|
}).then((response) => {
|
|
|
|
this.$emit('modified');
|
|
|
|
HelperModule.flashAlertMsg(response.data.message, 'success');
|
|
|
|
this.getAssignedUsers();
|
2023-12-11 22:41:03 +08:00
|
|
|
});
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
2023-12-11 22:41:03 +08:00
|
|
|
changeDefaultRole(roleId) {
|
2023-12-05 03:59:16 +08:00
|
|
|
axios.put(this.params.object.urls.default_public_user_role_path, {
|
2024-02-21 19:33:30 +08:00
|
|
|
object: {
|
2023-12-12 19:17:38 +08:00
|
|
|
default_public_user_role_id: roleId || ''
|
|
|
|
}
|
2023-12-05 03:59:16 +08:00
|
|
|
}).then((response) => {
|
|
|
|
this.$emit('modified');
|
2023-12-11 22:41:03 +08:00
|
|
|
if (!roleId) {
|
2023-12-05 03:59:16 +08:00
|
|
|
this.$emit('changeVisibility', false, null);
|
|
|
|
} else {
|
2023-12-11 22:41:03 +08:00
|
|
|
this.$emit('changeVisibility', true, roleId);
|
2023-12-05 03:59:16 +08:00
|
|
|
}
|
|
|
|
if (response.data.message) {
|
|
|
|
HelperModule.flashAlertMsg(response.data.message, 'success');
|
|
|
|
}
|
2023-12-11 22:41:03 +08:00
|
|
|
});
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
removeDefaultRole() {
|
2023-12-12 19:17:38 +08:00
|
|
|
}
|
|
|
|
}
|
2023-12-11 22:41:03 +08:00
|
|
|
};
|
2023-12-05 03:59:16 +08:00
|
|
|
</script>
|