Skip to content

Commit ec24f7a

Browse files
committed
feat(access-control): restrict company profile edit to owners/admins and display role
Add conditional rendering for edit button based on user role and show user role in sidebar
1 parent 5c7d9c5 commit ec24f7a

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

app/dashboard/company/[slug]/page.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,15 @@ export default function CompanySlugDashboardPage() {
164164
</p>
165165
</div>
166166
</div>
167-
<div className="pt-4">
168-
<Button asChild variant="outline">
169-
<Link href={`/dashboard/company/${currentCompany.slug}/settings`}>
170-
Edit Company Profile
171-
</Link>
172-
</Button>
173-
</div>
167+
{userRole && ['owner', 'admin'].includes(userRole) && (
168+
<div className="pt-4">
169+
<Button asChild variant="outline">
170+
<Link href={`/dashboard/company/${currentCompany.slug}/settings`}>
171+
Edit Company Profile
172+
</Link>
173+
</Button>
174+
</div>
175+
)}
174176
</CardContent>
175177
</Card>
176178
</div>

components/dashboard/CompanySidebar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function CompanySidebar({
7070
const toggleCollapsed = () => setCollapsed(!collapsed)
7171
const pathname = usePathname()
7272
const { navigateTo } = useSafeNavigation()
73-
const { currentCompany, userCompanies, switchCompany } = useCompanyContext()
73+
const { currentCompany, userCompanies, userRole, switchCompany } = useCompanyContext()
7474

7575
return (
7676
<SidebarProvider>
@@ -164,7 +164,7 @@ export function CompanySidebar({
164164
{name}
165165
</span>
166166
<span className="truncate text-xs text-purple-300">
167-
{currentCompany?.name}
167+
{userRole ? `${userRole.charAt(0).toUpperCase() + userRole.slice(1)}${currentCompany?.name}` : currentCompany?.name}
168168
</span>
169169
</div>
170170
<ChevronDown className="size-4 text-zinc-400" />
@@ -420,7 +420,7 @@ export function CompanySidebar({
420420
{name}
421421
</span>
422422
<span className="truncate text-xs text-purple-300">
423-
{currentCompany?.name}
423+
{userRole ? `${userRole.charAt(0).toUpperCase() + userRole.slice(1)}${currentCompany?.name}` : currentCompany?.name}
424424
</span>
425425
</div>
426426
<ChevronDown className="ml-auto size-4 text-zinc-400 flex-shrink-0" />

0 commit comments

Comments
 (0)