diff --git a/commit/commit/doctype/commit_docs/commit_docs.py b/commit/commit/doctype/commit_docs/commit_docs.py index 152e3bd..ddcfb68 100644 --- a/commit/commit/doctype/commit_docs/commit_docs.py +++ b/commit/commit/doctype/commit_docs/commit_docs.py @@ -88,19 +88,21 @@ def get_commit_docs_details(route:str): # 4. Get The Sidebar Items for the Commit Docs # 5. Return the Sidebar Items ''' - + user = frappe.session.user # Check if the Commit Docs Document Exists if frappe.db.exists('Commit Docs',{'route':route}): - # Check if the document is published - if frappe.db.get_value('Commit Docs',{'route':route},'published'): - # Get the Commit Docs Document + if user == "Guest": + if frappe.db.get_value('Commit Docs',{'route':route},'published'): + commit_docs = frappe.get_doc('Commit Docs',{'route':route}).as_dict() + + return parse_commit_docs(commit_docs) + else: + return frappe.throw('Docs Not Published') + else: commit_docs = frappe.get_doc('Commit Docs',{'route':route}).as_dict() return parse_commit_docs(commit_docs) - - else: - return frappe.throw('Docs Not Published') else: return frappe.throw('Docs Not Found') @@ -231,7 +233,7 @@ def get_group_items(commit_docs_page): # Check permissions and publication status permitted = group_commit_docs_page.allow_guest or frappe.session.user != 'Guest' - published = group_commit_docs_page.published + published = group_commit_docs_page.published or frappe.session.user != 'Guest' if not permitted or not published: continue @@ -252,7 +254,8 @@ def get_group_items(commit_docs_page): 'icon': group_commit_docs_page.icon, 'parent_name': commit_docs_page.name, 'is_group_page': True, - 'group_items': nested_group_items + 'group_items': nested_group_items, + "published":group_commit_docs_page.published }) else: # If it's a regular Docs Page, add it directly @@ -264,7 +267,8 @@ def get_group_items(commit_docs_page): 'badge': group_commit_docs_page.badge, 'badge_color': group_commit_docs_page.badge_color, 'icon': group_commit_docs_page.icon, - 'parent_name': commit_docs_page.name + 'parent_name': commit_docs_page.name, + "published":group_commit_docs_page.published }) # Add route to route_map route_map[group_commit_docs_page.route] = group_commit_docs_page.name @@ -278,7 +282,7 @@ def get_group_items(commit_docs_page): commit_docs_page = frappe.get_doc('Commit Docs Page', sidebar_item.docs_page) permitted = commit_docs_page.allow_guest or frappe.session.user != 'Guest' - published = commit_docs_page.published + published = commit_docs_page.published or frappe.session.user != 'Guest' is_group_page = commit_docs_page.is_group_page if not permitted or not published: @@ -298,7 +302,8 @@ def get_group_items(commit_docs_page): 'icon': commit_docs_page.icon, 'group_name': sidebar_item.parent_label, 'is_group_page': is_group_page, - 'group_items': group_items if is_group_page else None + 'group_items': group_items if is_group_page else None, + 'published': commit_docs_page.published } # Add sidebar entry to the parent label diff --git a/commit/commit/doctype/commit_docs_page/commit_docs_page.py b/commit/commit/doctype/commit_docs_page/commit_docs_page.py index 3726f55..25ff59f 100644 --- a/commit/commit/doctype/commit_docs_page/commit_docs_page.py +++ b/commit/commit/doctype/commit_docs_page/commit_docs_page.py @@ -98,8 +98,13 @@ def get_commit_docs_page(name): ''' Get the Commit Docs Page ''' + user = frappe.session.user + doc = frappe.get_doc('Commit Docs Page', name).as_dict() + if user == "Guest" and not doc.allow_guest and not doc.published: + frappe.throw("You are not allowed to view this page") + # Get the content as HTML html = frappe.utils.md_to_html(doc.content) diff --git a/dashboard/src/pages/features/docs/Sidebar.tsx b/dashboard/src/pages/features/docs/Sidebar.tsx index 51f661a..5774e5e 100644 --- a/dashboard/src/pages/features/docs/Sidebar.tsx +++ b/dashboard/src/pages/features/docs/Sidebar.tsx @@ -25,6 +25,11 @@ export const Sidebar = ({ ID }: { ID: string }) => { logo )} {commit_docs.header &&
{commit_docs.header}
} + {commit_docs.published == 0 && ( + + Draft + + )} {/* Sidebar Items */} {Object.keys(sidebar_items).map((key) => ( @@ -96,22 +101,22 @@ const SidebarTitle = ({ item, className, isExpanded, setIsExpanded }: { item: Do const badgeClass = classNames({ 'text-[10px] px-1 py-0': true, - 'bg-blue-500': item.badge_color === 'blue', - 'bg-red-500': item.badge_color === 'red', - 'bg-green-500': item.badge_color === 'green', - 'bg-yellow-500': item.badge_color === 'yellow', - 'bg-purple-500': item.badge_color === 'purple', - 'bg-pink-500': item.badge_color === 'pink', - 'bg-indigo-500': item.badge_color === 'indigo', - 'bg-cyan-500': item.badge_color === 'cyan', - 'bg-teal-500': item.badge_color === 'teal', - 'bg-lime-500': item.badge_color === 'lime', - 'bg-orange-500': item.badge_color === 'orange', - 'bg-blue-gray-500': item.badge_color === 'blue-gray', - 'bg-gray-500': item.badge_color === 'gray', - 'bg-true-gray-500': item.badge_color === 'true-gray', - 'bg-warm-gray-500': item.badge_color === 'warm-gray', - 'bg-cool-gray-500': item.badge_color === 'cool-gray', + 'bg-blue-500 hover:bg-blue-600': item.badge_color === 'blue', + 'bg-red-500 hover:bg-red-600': item.badge_color === 'red', + 'bg-green-500 hover:bg-green-600': item.badge_color === 'green', + 'bg-yellow-500 hover:bg-yellow-600': item.badge_color === 'yellow', + 'bg-purple-500 hover:bg-purple-600': item.badge_color === 'purple', + 'bg-pink-500 hover:bg-pink-600': item.badge_color === 'pink', + 'bg-indigo-500 hover:bg-indigo-600': item.badge_color === 'indigo', + 'bg-cyan-500 hover:bg-cyan-600': item.badge_color === 'cyan', + 'bg-teal-500 hover:bg-teal-600': item.badge_color === 'teal', + 'bg-lime-500 hover:bg-lime-600': item.badge_color === 'lime', + 'bg-orange-500 hover:bg-orange-600': item.badge_color === 'orange', + 'bg-blue-gray-500 hover:bg-blue-gray-600': item.badge_color === 'blue-gray', + 'bg-gray-500 hover:bg-gray-600': item.badge_color === 'gray', + 'bg-true-gray-500 hover:bg-true-gray-600': item.badge_color === 'true-gray', + 'bg-warm-gray-500 hover:bg-warm-gray-600': item.badge_color === 'warm-gray', + 'bg-cool-gray-500 hover:bg-cool-gray-600': item.badge_color === 'cool-gray', }) return ( @@ -139,7 +144,10 @@ const SidebarTitle = ({ item, className, isExpanded, setIsExpanded }: { item: Do {item.title} } - {item.is_group_page && item.group_items?.length ? {isExpanded ? : } : null} +
+ {item.published === 0 && Draft} + {item.is_group_page && item.group_items?.length ? {isExpanded ? : } : null} +
) diff --git a/dashboard/src/pages/features/docs/docs.ts b/dashboard/src/pages/features/docs/docs.ts index e2bc70c..7fd9692 100644 --- a/dashboard/src/pages/features/docs/docs.ts +++ b/dashboard/src/pages/features/docs/docs.ts @@ -10,7 +10,8 @@ export interface DocsSidebarItem { icon?: string parent_name?: string is_group_page?: boolean - group_items?: DocsSidebarItem[] + group_items?: DocsSidebarItem[], + published: 0 | 1 } export interface DocsNavbarItem {