feat: profile settings for roles
This commit is contained in:
@@ -116,7 +116,7 @@ const profile = createResource({
|
|||||||
|
|
||||||
const setActiveTab = () => {
|
const setActiveTab = () => {
|
||||||
let fragments = route.path.split('/')
|
let fragments = route.path.split('/')
|
||||||
let sections = ['certificates', 'settings']
|
let sections = ['certificates', 'settings', 'evaluator']
|
||||||
sections.forEach((section) => {
|
sections.forEach((section) => {
|
||||||
if (fragments.includes(section)) {
|
if (fragments.includes(section)) {
|
||||||
activeTab.value = convertToTitleCase(section)
|
activeTab.value = convertToTitleCase(section)
|
||||||
@@ -131,6 +131,7 @@ watchEffect(() => {
|
|||||||
About: { name: 'ProfileAbout' },
|
About: { name: 'ProfileAbout' },
|
||||||
Certificates: { name: 'ProfileCertificates' },
|
Certificates: { name: 'ProfileCertificates' },
|
||||||
Settings: { name: 'ProfileSettings' },
|
Settings: { name: 'ProfileSettings' },
|
||||||
|
Evaluato: { name: 'ProfileEvaluator' },
|
||||||
}[activeTab.value]
|
}[activeTab.value]
|
||||||
router.push(route)
|
router.push(route)
|
||||||
}
|
}
|
||||||
@@ -147,6 +148,8 @@ const isSessionUser = () => {
|
|||||||
const getTabButtons = () => {
|
const getTabButtons = () => {
|
||||||
let buttons = [{ label: 'About' }, { label: 'Certificates' }]
|
let buttons = [{ label: 'About' }, { label: 'Certificates' }]
|
||||||
if ($user.data?.is_moderator) buttons.push({ label: 'Settings' })
|
if ($user.data?.is_moderator) buttons.push({ label: 'Settings' })
|
||||||
|
if (isSessionUser() && $user.data?.is_evaluator)
|
||||||
|
buttons.push({ label: 'Evaluation Slots' })
|
||||||
|
|
||||||
return buttons
|
return buttons
|
||||||
}
|
}
|
||||||
|
|||||||
2
frontend/src/pages/ProfileEvaluator.vue
Normal file
2
frontend/src/pages/ProfileEvaluator.vue
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<template>Evaluator</template>
|
||||||
|
<script setup></script>
|
||||||
@@ -1 +1,96 @@
|
|||||||
<template></template>
|
<template>
|
||||||
|
<div class="mt-7">
|
||||||
|
<h2 class="mb-3 text-lg font-semibold text-gray-900">
|
||||||
|
{{ __('Settings') }}
|
||||||
|
</h2>
|
||||||
|
<div class="flex justify-between w-3/4 mt-5">
|
||||||
|
<FormControl
|
||||||
|
:label="__('Moderator')"
|
||||||
|
v-model="moderator"
|
||||||
|
type="checkbox"
|
||||||
|
@change.stop="changeRole('moderator')"
|
||||||
|
/>
|
||||||
|
<FormControl
|
||||||
|
:label="__('Course Creator')"
|
||||||
|
v-model="course_creator"
|
||||||
|
type="checkbox"
|
||||||
|
@change.stop="changeRole('course_creator')"
|
||||||
|
/>
|
||||||
|
<FormControl
|
||||||
|
:label="__('Evaluator')"
|
||||||
|
v-model="batch_evaluator"
|
||||||
|
type="checkbox"
|
||||||
|
@change.stop="changeRole('batch_evaluator')"
|
||||||
|
/>
|
||||||
|
<FormControl
|
||||||
|
:label="__('Student')"
|
||||||
|
v-model="lms_student"
|
||||||
|
type="checkbox"
|
||||||
|
@change.stop="changeRole('lms_student')"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script setup>
|
||||||
|
import { FormControl, createResource } from 'frappe-ui'
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import { showToast, convertToTitleCase } from '@/utils'
|
||||||
|
|
||||||
|
const moderator = ref(false)
|
||||||
|
const course_creator = ref(false)
|
||||||
|
const batch_evaluator = ref(false)
|
||||||
|
const lms_student = ref(false)
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
profile: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const roles = createResource({
|
||||||
|
url: 'lms.lms.utils.get_roles',
|
||||||
|
makeParams(values) {
|
||||||
|
return {
|
||||||
|
name: props.profile.data?.name,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
auto: true,
|
||||||
|
onSuccess(data) {
|
||||||
|
let roles = [
|
||||||
|
'moderator',
|
||||||
|
'course_creator',
|
||||||
|
'batch_evaluator',
|
||||||
|
'lms_student',
|
||||||
|
]
|
||||||
|
for (let role of roles) {
|
||||||
|
if (data[role]) eval(role).value = true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const updateRole = createResource({
|
||||||
|
url: 'lms.overrides.user.save_role',
|
||||||
|
makeParams(values) {
|
||||||
|
return {
|
||||||
|
user: props.profile.data?.name,
|
||||||
|
role: values.role,
|
||||||
|
value: values.value,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const changeRole = (role) => {
|
||||||
|
updateRole.submit(
|
||||||
|
{
|
||||||
|
role: convertToTitleCase(role.split('_').join(' ')),
|
||||||
|
value: eval(role).value,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSuccess(data) {
|
||||||
|
showToast('Success', 'Role updated successfully', 'check')
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|||||||
@@ -77,6 +77,11 @@ const routes = [
|
|||||||
path: 'settings',
|
path: 'settings',
|
||||||
component: () => import('@/pages/ProfileSettings.vue'),
|
component: () => import('@/pages/ProfileSettings.vue'),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'ProfileEvaluator',
|
||||||
|
path: 'evaluator',
|
||||||
|
component: () => import('@/pages/ProfileEvaluator.vue'),
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -90,11 +90,11 @@ def create_moderator_role():
|
|||||||
|
|
||||||
|
|
||||||
def create_evaluator_role():
|
def create_evaluator_role():
|
||||||
if not frappe.db.exists("Role", "Class Evaluator"):
|
if not frappe.db.exists("Role", "Batch Evaluator"):
|
||||||
role = frappe.new_doc("Role")
|
role = frappe.new_doc("Role")
|
||||||
role.update(
|
role.update(
|
||||||
{
|
{
|
||||||
"role_name": "Class Evaluator",
|
"role_name": "Batch Evaluator",
|
||||||
"home_page": "",
|
"home_page": "",
|
||||||
"desk_access": 0,
|
"desk_access": 0,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-07-13 11:30:22.641076",
|
"modified": "2024-04-15 11:21:52.182338",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "Course Evaluator",
|
"name": "Course Evaluator",
|
||||||
@@ -66,7 +66,7 @@
|
|||||||
"print": 1,
|
"print": 1,
|
||||||
"read": 1,
|
"read": 1,
|
||||||
"report": 1,
|
"report": 1,
|
||||||
"role": "Class Evaluator",
|
"role": "Batch Evaluator",
|
||||||
"share": 1,
|
"share": 1,
|
||||||
"write": 1
|
"write": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@
|
|||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-12-18 20:03:27.040073",
|
"modified": "2024-04-15 11:22:43.189908",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "LMS Certificate Evaluation",
|
"name": "LMS Certificate Evaluation",
|
||||||
@@ -133,7 +133,7 @@
|
|||||||
"print": 1,
|
"print": 1,
|
||||||
"read": 1,
|
"read": 1,
|
||||||
"report": 1,
|
"report": 1,
|
||||||
"role": "Class Evaluator",
|
"role": "Batch Evaluator",
|
||||||
"share": 1,
|
"share": 1,
|
||||||
"write": 1
|
"write": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,7 +109,7 @@
|
|||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2024-01-09 10:05:13.918890",
|
"modified": "2024-04-15 11:23:03.933035",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "LMS Certificate Request",
|
"name": "LMS Certificate Request",
|
||||||
@@ -128,18 +128,6 @@
|
|||||||
"share": 1,
|
"share": 1,
|
||||||
"write": 1
|
"write": 1
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"create": 1,
|
|
||||||
"delete": 1,
|
|
||||||
"email": 1,
|
|
||||||
"export": 1,
|
|
||||||
"print": 1,
|
|
||||||
"read": 1,
|
|
||||||
"report": 1,
|
|
||||||
"role": "Class Evaluator",
|
|
||||||
"share": 1,
|
|
||||||
"write": 1
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"create": 1,
|
"create": 1,
|
||||||
"delete": 1,
|
"delete": 1,
|
||||||
@@ -161,6 +149,18 @@
|
|||||||
"report": 1,
|
"report": 1,
|
||||||
"role": "LMS Student",
|
"role": "LMS Student",
|
||||||
"share": 1
|
"share": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"create": 1,
|
||||||
|
"delete": 1,
|
||||||
|
"email": 1,
|
||||||
|
"export": 1,
|
||||||
|
"print": 1,
|
||||||
|
"read": 1,
|
||||||
|
"report": 1,
|
||||||
|
"role": "Batch Evaluator",
|
||||||
|
"share": 1,
|
||||||
|
"write": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
|
|||||||
@@ -577,7 +577,15 @@ def has_course_moderator_role(member=None):
|
|||||||
def has_course_evaluator_role(member=None):
|
def has_course_evaluator_role(member=None):
|
||||||
return frappe.db.get_value(
|
return frappe.db.get_value(
|
||||||
"Has Role",
|
"Has Role",
|
||||||
{"parent": member or frappe.session.user, "role": "Class Evaluator"},
|
{"parent": member or frappe.session.user, "role": "Batch Evaluator"},
|
||||||
|
"name",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def has_student_role(member=None):
|
||||||
|
return frappe.db.get_value(
|
||||||
|
"Has Role",
|
||||||
|
{"parent": member or frappe.session.user, "role": "LMS Student"},
|
||||||
"name",
|
"name",
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1780,3 +1788,14 @@ def get_lesson_creation_details(course, chapter, lesson):
|
|||||||
),
|
),
|
||||||
"lesson": lesson_details if lesson_name else None,
|
"lesson": lesson_details if lesson_name else None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_roles(name):
|
||||||
|
frappe.only_for("Moderator")
|
||||||
|
return {
|
||||||
|
"moderator": has_course_moderator_role(name),
|
||||||
|
"course_creator": has_course_instructor_role(name),
|
||||||
|
"class_evaluator": has_course_evaluator_role(name),
|
||||||
|
"lms_student": has_student_role(name),
|
||||||
|
}
|
||||||
|
|||||||
@@ -356,6 +356,7 @@ def get_users(or_filters, start, page_length):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def save_role(user, role, value):
|
def save_role(user, role, value):
|
||||||
|
frappe.only_for("Moderator")
|
||||||
if cint(value):
|
if cint(value):
|
||||||
doc = frappe.get_doc(
|
doc = frappe.get_doc(
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user