fix: permission issues on badges

This commit is contained in:
Jannat Patel
2026-02-19 15:59:03 +05:30
parent 08373dc2ab
commit c88d36df1e
6 changed files with 47 additions and 113 deletions

View File

@@ -1,82 +0,0 @@
<template>
<div v-if="badge.data">
<div class="p-5 flex flex-col items-center mt-40">
<div class="text-3xl font-semibold">
{{ badge.data.badge }}
</div>
<img
:src="badge.data.badge_image"
:alt="badge.data.badge"
class="h-60 mt-2"
/>
<div class="">
{{
__('This badge has been awarded to {0} on {1}.').format(
badge.data.member_name,
dayjs(badge.data.issued_on).format('DD MMM YYYY')
)
}}
</div>
<div class="mt-2">
{{ badge.data.badge_description }}
</div>
</div>
</div>
</template>
<script setup>
import { createResource, usePageMeta } from 'frappe-ui'
import { computed, inject } from 'vue'
import { sessionStore } from '../stores/session'
const dayjs = inject('$dayjs')
const { brand } = sessionStore()
const props = defineProps({
badgeName: {
type: String,
required: true,
},
email: {
type: String,
required: true,
},
})
const badge = createResource({
url: 'frappe.client.get',
makeParams(values) {
return {
doctype: 'LMS Badge Assignment',
filters: {
badge: props.badgeName,
member: props.email,
},
}
},
auto: true,
})
const breadcrumbs = computed(() => {
return [
{
label: __('Badges'),
},
{
label: badge.data.badge,
route: {
name: 'Badge',
params: {
badge: badge.data.badge,
},
},
},
]
})
usePageMeta(() => {
return {
title: badge.data.badge,
icon: brand.favicon,
}
})
</script>

View File

@@ -70,13 +70,16 @@
<div class="leading-5 mb-4"> <div class="leading-5 mb-4">
{{ badge.badge_description }} {{ badge.badge_description }}
</div> </div>
<div class="flex flex-col mb-4"> <div class="flex flex-col">
<span class="text-xs text-ink-gray-7 font-medium mb-1"> <span class="text-xs text-ink-gray-7 font-medium mb-1">
{{ __('Issued on') }}: {{ __('Issued on') }}:
</span> </span>
{{ dayjs(badge.issued_on).format('DD MMM YYYY') }} {{ dayjs(badge.issued_on).format('DD MMM YYYY') }}
</div> </div>
<div class="flex flex-col"> <div
v-if="user.data?.name == profile.data?.name"
class="flex flex-col mt-4"
>
<span class="text-xs text-ink-gray-7 font-medium mb-1"> <span class="text-xs text-ink-gray-7 font-medium mb-1">
{{ __('Share on') }}: {{ __('Share on') }}:
</span> </span>
@@ -125,6 +128,7 @@ import DOMPurify from 'dompurify'
import { getLmsRoute } from '@/utils/basePath' import { getLmsRoute } from '@/utils/basePath'
const dayjs = inject('$dayjs') const dayjs = inject('$dayjs')
const user = inject('$user')
const { branding } = sessionStore() const { branding } = sessionStore()
const props = defineProps({ const props = defineProps({
@@ -135,13 +139,9 @@ const props = defineProps({
}) })
const badges = createResource({ const badges = createResource({
url: 'frappe.client.get_list', url: 'lms.lms.api.get_badges',
params: { params: {
doctype: 'LMS Badge Assignment', member: props.profile.data.name,
fields: ['name', 'badge', 'badge_image', 'badge_description', 'issued_on'],
filters: {
member: props.profile.data.name,
},
}, },
auto: true, auto: true,
transform(data) { transform(data) {
@@ -160,14 +160,16 @@ const shareOnSocial = (badge, medium) => {
let shareUrl let shareUrl
const url = encodeURIComponent( const url = encodeURIComponent(
`${window.location.origin}${getLmsRoute( `${window.location.origin}${getLmsRoute(
`badges/${badge.badge}/${props.profile.data?.email}` `user/${props.profile.data?.username}`
)}` )}`
) )
const summary = `I am happy to announce that I earned the ${ const summary = __(
badge.badge 'I am happy to announce that I earned the {0} badge on {1} at {2}'
} badge on ${dayjs(badge.issued_on).format('DD MMM YYYY')} at ${ ).format(
badge.badge,
dayjs(badge.issued_on).format('DD MMM YYYY'),
branding.data?.app_name branding.data?.app_name
}.` )
if (medium == 'LinkedIn') if (medium == 'LinkedIn')
shareUrl = `https://www.linkedin.com/shareArticle?mini=true&url=${url}&text=${summary}` shareUrl = `https://www.linkedin.com/shareArticle?mini=true&url=${url}&text=${summary}`

View File

@@ -1298,6 +1298,7 @@ def get_lms_settings():
"contact_us_url", "contact_us_url",
"livecode_url", "livecode_url",
"disable_pwa", "disable_pwa",
"allow_job_posting",
] ]
settings = frappe._dict() settings = frappe._dict()
@@ -1310,7 +1311,6 @@ def get_lms_settings():
@frappe.whitelist() @frappe.whitelist()
def cancel_evaluation(evaluation: dict): def cancel_evaluation(evaluation: dict):
evaluation = frappe._dict(evaluation) evaluation = frappe._dict(evaluation)
print(evaluation.member, frappe.session.user)
if evaluation.member != frappe.session.user: if evaluation.member != frappe.session.user:
frappe.throw(_("You do not have permission to cancel this evaluation."), frappe.PermissionError) frappe.throw(_("You do not have permission to cancel this evaluation."), frappe.PermissionError)
@@ -2219,3 +2219,17 @@ def get_assessment_from_lesson(course: str, assessmentType: str):
assessments.append(quiz_name) assessments.append(quiz_name)
return assessments return assessments
@frappe.whitelist()
def get_badges(member: str):
if not has_lms_role(frappe.get_roles()):
frappe.throw(_("You do not have permission to access badges."), frappe.PermissionError)
badges = frappe.get_all(
"LMS Badge Assignment",
{"member": member},
["name", "member", "badge", "badge_image", "badge_description", "issued_on"],
)
return badges

View File

@@ -100,7 +100,7 @@
"link_fieldname": "badge" "link_fieldname": "badge"
} }
], ],
"modified": "2026-02-19 12:04:56.263316", "modified": "2026-02-19 15:05:49.719925",
"modified_by": "sayali@frappe.io", "modified_by": "sayali@frappe.io",
"module": "LMS", "module": "LMS",
"name": "LMS Badge", "name": "LMS Badge",
@@ -131,15 +131,6 @@
"role": "Moderator", "role": "Moderator",
"share": 1, "share": 1,
"write": 1 "write": 1
},
{
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "LMS Student",
"share": 1
} }
], ],
"row_format": "Dynamic", "row_format": "Dynamic",

View File

@@ -84,7 +84,7 @@
"grid_page_length": 50, "grid_page_length": 50,
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2025-12-04 17:06:26.090276", "modified": "2026-02-19 15:06:08.389081",
"modified_by": "sayali@frappe.io", "modified_by": "sayali@frappe.io",
"module": "LMS", "module": "LMS",
"name": "LMS Badge Assignment", "name": "LMS Badge Assignment",
@@ -120,10 +120,6 @@
"read": 1, "read": 1,
"role": "LMS Student" "role": "LMS Student"
}, },
{
"read": 1,
"role": "LMS Student"
},
{ {
"create": 1, "create": 1,
"delete": 1, "delete": 1,

View File

@@ -76,7 +76,9 @@
"contact_us_tab", "contact_us_tab",
"contact_us_email", "contact_us_email",
"column_break_gcgv", "column_break_gcgv",
"contact_us_url" "contact_us_url",
"jobs_tab",
"allow_job_posting"
], ],
"fields": [ "fields": [
{ {
@@ -471,13 +473,24 @@
{ {
"fieldname": "column_break_dtns", "fieldname": "column_break_dtns",
"fieldtype": "Column Break" "fieldtype": "Column Break"
},
{
"fieldname": "jobs_tab",
"fieldtype": "Tab Break",
"label": "Jobs"
},
{
"default": "1",
"fieldname": "allow_job_posting",
"fieldtype": "Check",
"label": "Allow Job Posting"
} }
], ],
"grid_page_length": 50, "grid_page_length": 50,
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"issingle": 1, "issingle": 1,
"links": [], "links": [],
"modified": "2026-01-01 19:36:54.443390", "modified": "2026-02-19 12:57:28.499184",
"modified_by": "sayali@frappe.io", "modified_by": "sayali@frappe.io",
"module": "LMS", "module": "LMS",
"name": "LMS Settings", "name": "LMS Settings",