Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions commit/commit/doctype/commit_docs/commit_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions commit/commit/doctype/commit_docs_page/commit_docs_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
42 changes: 25 additions & 17 deletions dashboard/src/pages/features/docs/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export const Sidebar = ({ ID }: { ID: string }) => {
<img src={commit_docs.light_mode_logo} alt="logo" className="h-8" />
)}
{commit_docs.header && <div className="text-lg font-bold">{commit_docs.header}</div>}
{commit_docs.published == 0 && (
<Badge className="px-1 py-0 bg-orange-500">
Draft
</Badge>
)}
</div>
{/* Sidebar Items */}
{Object.keys(sidebar_items).map((key) => (
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -139,7 +144,10 @@ const SidebarTitle = ({ item, className, isExpanded, setIsExpanded }: { item: Do
{item.title}
</div>
</a>}
{item.is_group_page && item.group_items?.length ? <span>{isExpanded ? <ChevronDown className={'h-4'} /> : <ChevronRight className={'h-4'} />}</span> : null}
<div className="flex flex-row gap-2 items-center">
{item.published === 0 && <Badge className="px-1 py-0 bg-orange-500 hover:bg-orange-600">Draft</Badge>}
{item.is_group_page && item.group_items?.length ? <span>{isExpanded ? <ChevronDown className={'h-4'} /> : <ChevronRight className={'h-4'} />}</span> : null}
</div>
</div>
</div>
)
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/pages/features/docs/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down