fix: profile settings
This commit is contained in:
@@ -13,7 +13,9 @@
|
||||
"mentor_request_status_update",
|
||||
"search_settings_section",
|
||||
"show_search",
|
||||
"search_placeholder"
|
||||
"search_placeholder",
|
||||
"profile_restrictions_section",
|
||||
"force_profile_completion"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -65,12 +67,23 @@
|
||||
"fieldname": "search_placeholder",
|
||||
"fieldtype": "Data",
|
||||
"label": "Search Field Placeholder"
|
||||
},
|
||||
{
|
||||
"fieldname": "profile_restrictions_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Profile Restrictions"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "force_profile_completion",
|
||||
"fieldtype": "Check",
|
||||
"label": "Force users to complete their Profile"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2021-11-25 14:12:21.514922",
|
||||
"modified": "2021-12-15 11:30:06.506403",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Settings",
|
||||
|
||||
@@ -3,8 +3,18 @@
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
# import frappe
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class LMSSettings(Document):
|
||||
pass
|
||||
|
||||
@frappe.whitelist()
|
||||
def check_profile_restriction():
|
||||
force_profile_completion = frappe.db.get_single_value("LMS Settings", "force_profile_completion")
|
||||
user = frappe.db.get_value("User", frappe.session.user, ["profile_complete", "username"], as_dict=True)
|
||||
return {
|
||||
"redirect": force_profile_completion and not user.profile_complete,
|
||||
"username": user.username,
|
||||
"prefix": frappe.get_hooks("profile_url_prefix") or "/users/"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,24 @@
|
||||
frappe.ready(() => {
|
||||
hide_profile_for_guest_users();
|
||||
restrict_users_to_profile_page();
|
||||
});
|
||||
|
||||
const hide_profile_for_guest_users = () => {
|
||||
if (frappe.session.user == "Guest") {
|
||||
var link_array = $('.nav-link').filter((i, elem) => $(elem).text().trim() === "My Profile");
|
||||
link_array.length && $(link_array[0]).addClass("hide");
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
const restrict_users_to_profile_page = () => {
|
||||
if (frappe.session.user != "Guest") {
|
||||
frappe.call({
|
||||
"method": "school.lms.doctype.lms_settings.lms_settings.check_profile_restriction",
|
||||
"callback": (data) => {
|
||||
if (data.message && data.message.redirect) {
|
||||
window.location.href = `${data.message.prefix}${data.message.username}`;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user