Skip to content

Commit ce93b84

Browse files
committed
Request-a-copy: Code cleanup and comments
1 parent c9c2a77 commit ce93b84

3 files changed

Lines changed: 20 additions & 38 deletions

File tree

src/app/app-routing-paths.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,19 @@ export function getBitstreamRequestACopyRoute(item, bitstream): { routerLink: st
3434
},
3535
};
3636
}
37+
38+
/**
39+
* Get a bitstream download route with an access token (to provide direct access to a user) added as a query parameter
40+
* @param bitstream the bitstream to download
41+
* @param accessToken the access token, which should match an access_token in the requestitem table
42+
*/
3743
export function getBitstreamDownloadWithAccessTokenRoute(bitstream, accessToken): { routerLink: string, queryParams: any } {
3844
const url = new URLCombiner(getBitstreamModuleRoute(), bitstream.uuid, 'download').toString();
3945
const options = {
4046
routerLink: url,
4147
queryParams: {},
4248
};
49+
// Only add the access token if it is not empty, otherwise keep valid empty query parameters
4350
if (hasValue(accessToken)) {
4451
options.queryParams = { accessToken: accessToken };
4552
}
@@ -60,21 +67,7 @@ export function getAccessTokenRequestRoute(item_uuid, accessToken): { routerLink
6067
};
6168
return options;
6269
}
63-
/**
64-
* Get an access token request route for a user to access approved bitstreams using a supplied access token
65-
* @param item_uuid item UUID
66-
* @param accessToken access token (generated by backend)
67-
*/
68-
export function getAccessTokenRequestFileRoute(item_uuid, accessToken): { routerLink: string, queryParams: any } {
69-
const url = new URLCombiner(getItemModuleRoute(), item_uuid, ACCESS_BY_TOKEN_MODULE_PATH).toString();
70-
const options = {
71-
routerLink: url,
72-
queryParams: {
73-
accessToken: (hasValue(accessToken) ? accessToken : undefined),
74-
},
75-
};
76-
return options;
77-
}
70+
7871
export const COAR_NOTIFY_SUPPORT = 'coar-notify-support';
7972

8073
export const HOME_PAGE_PATH = 'home';

src/app/bitstream-page/bitstream-download-page/bitstream-download-page.component.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,13 @@ export class BitstreamDownloadPageComponent implements OnInit {
9393
map((data) => data.bitstream));
9494

9595
this.bitstream$ = this.bitstreamRD$.pipe(
96-
// TODO: this redirect was commented out earlier...
9796
redirectOn4xx(this.router, this.auth),
9897
getRemoteDataPayload(),
9998
);
10099

101100
this.bitstream$.pipe(
102101
switchMap((bitstream: Bitstream) => {
103102
const isAuthorized$ = this.authorizationService.isAuthorized(FeatureID.CanDownload, isNotEmpty(bitstream) ? bitstream.self : undefined);
104-
// TODO isAuthorizedByToken check here so we already know if this token is going to be valid?
105103
const isLoggedIn$ = this.auth.isAuthenticated();
106104
return observableCombineLatest([isAuthorized$, isLoggedIn$, accessToken$, observableOf(bitstream)]);
107105
}),
@@ -116,32 +114,12 @@ export class BitstreamDownloadPageComponent implements OnInit {
116114
return [isAuthorized, isLoggedIn, bitstream, fileLink];
117115
}));
118116
} else if (hasValue(accessToken)) {
119-
// We aren't authorized or logged in, but we might have temp access via the access token
120-
console.log('RETRIEVE WITH ACCESS TOKEN');
121-
console.log('BUT - we dont want to retrieve the link with access token eh bro');
122-
// return this.fileService.retrieveFileDownloadLinkWithAccessToken(bitstream._links.content.href, accessToken).pipe(
123-
// filter((fileLink) => hasValue(fileLink)),
124-
// take(1),
125-
// map((fileLink) => {
126-
// return [isAuthorized, isLoggedIn, bitstream, fileLink];
127-
// }));
128117
return [[isAuthorized, !isLoggedIn, bitstream, '', accessToken]];
129118
} else {
130119
return [[isAuthorized, isLoggedIn, bitstream, '']];
131120
}
132121
}),
133122
).subscribe(([isAuthorized, isLoggedIn, bitstream, fileLink, accessToken]: [boolean, boolean, Bitstream, string, string]) => {
134-
// if (isAuthorized && isLoggedIn && isNotEmpty(fileLink)) {
135-
// this.hardRedirectService.redirect(fileLink);
136-
// } else if (isAuthorized && !isLoggedIn) {
137-
// this.hardRedirectService.redirect(bitstream._links.content.href);
138-
// } else if (!isAuthorized && isLoggedIn) {
139-
// this.router.navigateByUrl(getForbiddenRoute(), {skipLocationChange: true});
140-
// } else if (!isAuthorized && !isLoggedIn) {
141-
// this.auth.setRedirectUrl(this.router.url);
142-
// this.router.navigateByUrl('login');
143-
// }
144-
145123
if (isAuthorized && isLoggedIn && isNotEmpty(fileLink)) {
146124
this.hardRedirectService.redirect(fileLink);
147125
} else if (isAuthorized && !isLoggedIn && !hasValue(accessToken)) {

src/app/item-page/bitstreams/request-a-copy/altcha-captcha.component.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,22 @@ import { VarDirective } from '../../../shared/utils/var.directive';
3030
schemas: [CUSTOM_ELEMENTS_SCHEMA],
3131
standalone: true,
3232
})
33+
34+
/**
35+
* Component that renders the ALTCHA captcha widget. GDPR-compliant, no cookies, proof-of-work based anti-spam captcha.
36+
* See: https://altcha.org/
37+
*
38+
* Once the proof of work is verified, the final payload is emitted to the parent component for inclusion in the form submission.
39+
*/
3340
export class AltchaCaptchaComponent implements OnInit {
3441

42+
// Challenge URL, to query the backend (or other remote) for a challenge
3543
@Input() challengeUrl: string;
36-
@Input() autoload: string;
44+
// Whether / how to autoload the widget, e.g. 'onload', 'onsubmit', 'onfocus', 'off'
45+
@Input() autoload = 'onload';
46+
// Whether to debug altcha activity to the javascript console
3747
@Input() debug: boolean;
48+
// The final calculated payload (containing, challenge, salt, number) to be sent with the protected form submission for validation
3849
@Output() payload = new EventEmitter<string>;
3950

4051
ngOnInit(): void {

0 commit comments

Comments
 (0)