diff --git a/src/app/components/dashboard/dashboard.html b/src/app/components/dashboard/dashboard.html
index f39c299..515456e 100644
--- a/src/app/components/dashboard/dashboard.html
+++ b/src/app/components/dashboard/dashboard.html
@@ -37,7 +37,7 @@
{{ ws.name }}
Created: {{ ws.createdDate | date: 'mediumDate' }}
diff --git a/src/app/components/dashboard/dashboard.spec.ts b/src/app/components/dashboard/dashboard.spec.ts
index c5f36f4..e2b3827 100644
--- a/src/app/components/dashboard/dashboard.spec.ts
+++ b/src/app/components/dashboard/dashboard.spec.ts
@@ -23,7 +23,8 @@ describe('Dashboard', () => {
};
mockAuthService = {
- logout: jasmine.createSpy('logout')
+ logout: jasmine.createSpy('logout'),
+ getCurrentUserId: jasmine.createSpy('getCurrentUserId').and.returnValue('u1')
};
mockSignalService = {
@@ -91,6 +92,24 @@ describe('Dashboard', () => {
expect(compiled.querySelector('.workspace-card h3')?.textContent).toContain('Test Workspace');
});
+ it('should hide edit action for workspaces not owned by the current user', () => {
+ mockWorkspaceService.getWorkspaces.and.returnValue(of([
+ { id: '1', name: 'Owned Workspace', description: 'Owned Desc', createdDate: new Date(), ownerId: 'u1' },
+ { id: '2', name: 'Shared Workspace', description: 'Shared Desc', createdDate: new Date(), ownerId: 'u2' }
+ ]));
+
+ fixture = TestBed.createComponent(Dashboard);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+
+ const cards = Array.from(fixture.nativeElement.querySelectorAll('.workspace-card')) as HTMLElement[];
+ const ownedCard = cards.find(card => card.textContent?.includes('Owned Workspace'));
+ const sharedCard = cards.find(card => card.textContent?.includes('Shared Workspace'));
+
+ expect(ownedCard?.textContent).toContain('Edit');
+ expect(sharedCard?.textContent).not.toContain('Edit');
+ });
+
it('should call logout on button click', () => {
const button = fixture.nativeElement.querySelector('.logout-btn');
button.click();
diff --git a/src/app/components/dashboard/dashboard.ts b/src/app/components/dashboard/dashboard.ts
index 349ae97..7909b63 100644
--- a/src/app/components/dashboard/dashboard.ts
+++ b/src/app/components/dashboard/dashboard.ts
@@ -29,8 +29,11 @@ export class Dashboard implements OnInit {
filters: SignalFilters = { source: 'all', status: 'all' };
githubBanner = '';
slackBanner = '';
+ currentUserId: string | null = null;
ngOnInit() {
+ this.currentUserId = this.authService.getCurrentUserId();
+
this.workspaceService.getWorkspaces().subscribe({
next: ws => {
this.workspaces = ws;
@@ -57,6 +60,10 @@ export class Dashboard implements OnInit {
this.loadSignals();
}
+ canEditWorkspace(workspace: Workspace): boolean {
+ return this.currentUserId !== null && workspace.ownerId === this.currentUserId;
+ }
+
deleteWorkspace(workspace: Workspace) {
const confirmed = window.confirm(`Delete workspace "${workspace.name}"?`);
if (!confirmed) {
@@ -68,6 +75,7 @@ export class Dashboard implements OnInit {
return;
}
this.workspaces = this.workspaces.filter(ws => ws.id !== workspace.id);
+ this.cdr.detectChanges();
});
}
@@ -97,6 +105,7 @@ export class Dashboard implements OnInit {
private loadSignals(): void {
this.signalService.getSignals(this.filters).subscribe(signals => {
this.signals = signals;
+ this.cdr.detectChanges();
});
}
}
diff --git a/src/app/components/workspace/edit-workspace.html b/src/app/components/workspace/edit-workspace.html
index fc328b8..dea5561 100644
--- a/src/app/components/workspace/edit-workspace.html
+++ b/src/app/components/workspace/edit-workspace.html
@@ -24,7 +24,7 @@ Edit Workspace
Loading workspace...
-