Skip to content

Commit 2f8a424

Browse files
committed
Change to a different archive when accepting a share
When a share is restricted, the user either needs to accept the share or request access. In the process, the user can also choose to which archive the share will be added. This commit adds the share to the correct archive. Issue: PER-10322
1 parent 9900b53 commit 2f8a424

File tree

2 files changed

+86
-14
lines changed

2 files changed

+86
-14
lines changed

src/app/share-preview/components/share-preview/share-preview.component.spec.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { ApiService } from '@shared/services/api/api.service';
2525
import { GoogleAnalyticsService } from '@shared/services/google-analytics/google-analytics.service';
2626
import { ShareResponse } from '@shared/services/api/share.repo';
2727
import { FilesystemService } from '@root/app/filesystem/filesystem.service';
28+
import { MessageService } from '@shared/services/message/message.service';
2829
import { CreateAccountDialogComponent } from '../create-account-dialog/create-account-dialog.component';
2930
import { SharePreviewComponent } from './share-preview.component';
3031

@@ -77,6 +78,10 @@ const mockFilesystemService = {
7778
getFolder: jasmine.createSpy().and.returnValue(Promise.resolve({})),
7879
};
7980

81+
const mockMessageService = {
82+
showMessage: jasmine.createSpy(),
83+
};
84+
8085
describe('SharePreviewComponent', () => {
8186
let component: SharePreviewComponent;
8287
let fixture: ComponentFixture<SharePreviewComponent>;
@@ -133,6 +138,11 @@ describe('SharePreviewComponent', () => {
133138
useValue: mockFilesystemService,
134139
});
135140

141+
config.providers.push({
142+
provide: MessageService,
143+
useValue: mockMessageService,
144+
});
145+
136146
await TestBed.configureTestingModule(config).compileComponents();
137147

138148
dialog = TestBed.inject(DialogCdkService);
@@ -334,4 +344,55 @@ describe('SharePreviewComponent', () => {
334344
expect(component.hasRequested).toBeTrue();
335345
expect(component.showCover).toBeFalse();
336346
}));
347+
348+
it('should request access and show pending message when status is pending', fakeAsync(() => {
349+
const mockResponse = {
350+
getShareVO: () => ({ status: 'status.generic.pending' }),
351+
};
352+
spyOn(apiService.share, 'requestShareAccess').and.returnValue(
353+
Promise.resolve(mockResponse as any),
354+
);
355+
356+
component.shareToken = 'mock-token';
357+
component.shareAccount = { fullName: 'Sharer Name' } as any;
358+
359+
component.requestShareAccess();
360+
tick();
361+
362+
expect(apiService.share.requestShareAccess).toHaveBeenCalledWith(
363+
'mock-token',
364+
);
365+
366+
expect(mockMessageService.showMessage).toHaveBeenCalledWith({
367+
message: 'Access requested. Sharer Name must approve your request.',
368+
style: 'success',
369+
});
370+
371+
expect(component.showCover).toBeFalse();
372+
expect(component.hasRequested).toBeTrue();
373+
}));
374+
375+
it('should show access granted message and navigate when status is not pending', fakeAsync(() => {
376+
const mockResponse = {
377+
getShareVO: () => ({ status: 'ok' }),
378+
};
379+
spyOn(apiService.share, 'requestShareAccess').and.returnValue(
380+
Promise.resolve(mockResponse as any),
381+
);
382+
const routerSpy = spyOn(router, 'navigate');
383+
component.shareToken = 'mock-token';
384+
component.requestShareAccess();
385+
tick();
386+
387+
expect(apiService.share.requestShareAccess).toHaveBeenCalledWith(
388+
'mock-token',
389+
);
390+
391+
expect(mockMessageService.showMessage).toHaveBeenCalledWith({
392+
message: 'Access granted.',
393+
style: 'success',
394+
});
395+
396+
expect(routerSpy).toHaveBeenCalledWith(['/app', 'shares']);
397+
}));
337398
});

src/app/share-preview/components/share-preview/share-preview.component.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -468,29 +468,21 @@ export class SharePreviewComponent implements OnInit, OnDestroy {
468468
}
469469

470470
async onRequestAccessClick() {
471+
let dialogRef;
471472
try {
472473
this.waiting = true;
473474
if (!this.archiveConfirmed) {
474-
await this.accountService.promptForArchiveChange(
475+
dialogRef = await this.accountService.promptForArchiveChange(
475476
this.chooseArchiveText,
476477
);
477478
this.archiveConfirmed = true;
478479
}
479-
const response = await this.api.share.requestShareAccess(this.shareToken);
480-
const shareVo = response.getShareVO();
481-
if (shareVo.status === 'status.generic.pending') {
482-
this.message.showMessage({
483-
message: `Access requested. ${this.shareAccount.fullName} must approve your request.`,
484-
style: 'success',
480+
if (dialogRef) {
481+
dialogRef.closed.subscribe(async () => {
482+
await this.requestShareAccess();
485483
});
486-
this.showCover = false;
487-
this.hasRequested = true;
488484
} else {
489-
this.message.showMessage({
490-
message: 'Access granted.',
491-
style: 'success',
492-
});
493-
this.router.navigate(['/app', 'shares']);
485+
await this.requestShareAccess();
494486
}
495487
} catch (err) {
496488
if (err instanceof ShareResponse) {
@@ -510,6 +502,25 @@ export class SharePreviewComponent implements OnInit, OnDestroy {
510502
}
511503
}
512504

505+
async requestShareAccess() {
506+
const response = await this.api.share.requestShareAccess(this.shareToken);
507+
const shareVo = response.getShareVO();
508+
if (shareVo.status === 'status.generic.pending') {
509+
this.message.showMessage({
510+
message: `Access requested. ${this.shareAccount.fullName} must approve your request.`,
511+
style: 'success',
512+
});
513+
this.showCover = false;
514+
this.hasRequested = true;
515+
} else {
516+
this.message.showMessage({
517+
message: 'Access granted.',
518+
style: 'success',
519+
});
520+
this.router.navigate(['/app', 'shares']);
521+
}
522+
}
523+
513524
onSignupSubmit(formValue: any) {
514525
this.waiting = true;
515526

0 commit comments

Comments
 (0)