Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unauthorised community/collection logo fix #2689

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div *ngIf="logo" class="dso-logo mb-3">
<img [src]="logo._links.content.href" class="img-fluid" [attr.alt]="alternateText ? alternateText : null" (error)="errorHandler($event)"/>
<img [src]="logo?._links?.content?.href" class="img-fluid" [class.d-none]="loading" [attr.alt]="alternateText ? alternateText : null" (error)="errorHandler($event)"/>
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Component, Input } from '@angular/core';

import { Bitstream } from '../../../core/shared/bitstream.model';
import { AuthService } from '../../../core/auth/auth.service';
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
import { FileService } from '../../../core/shared/file.service';
import { of as observableOf } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
import { hasValue } from '../../empty.util';

@Component({
selector: 'ds-comcol-page-logo',
Expand All @@ -12,13 +19,58 @@

@Input() alternateText: string;

/**
* Flag used to hide the image element while resolving an error into placeholder or authorised image
*/
loading = false;

Check warning on line 25 in src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts#L25

Added line #L25 was not covered by tests

/**
* The default 'holder.js' image
*/
holderSource = 'data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2293%22%20height%3D%22120%22%20viewBox%3D%220%200%2093%20120%22%20preserveAspectRatio%3D%22none%22%3E%3C!--%0ASource%20URL%3A%20holder.js%2F93x120%3Ftext%3DNo%20Thumbnail%0ACreated%20with%20Holder.js%202.8.2.%0ALearn%20more%20at%20http%3A%2F%2Fholderjs.com%0A(c)%202012-2015%20Ivan%20Malopinsky%20-%20http%3A%2F%2Fimsky.co%0A--%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%3C!%5BCDATA%5B%23holder_1543e460b05%20text%20%7B%20fill%3A%23AAAAAA%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A10pt%20%7D%20%5D%5D%3E%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_1543e460b05%22%3E%3Crect%20width%3D%2293%22%20height%3D%22120%22%20fill%3D%22%23EEEEEE%22%2F%3E%3Cg%3E%3Ctext%20x%3D%2235.6171875%22%20y%3D%2257%22%3ENo%3C%2Ftext%3E%3Ctext%20x%3D%2210.8125%22%20y%3D%2272%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E';

constructor(
protected auth: AuthService,
protected authorizationService: AuthorizationDataService,
protected fileService: FileService,

Check warning on line 35 in src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts#L33-L35

Added lines #L33 - L35 were not covered by tests
) {
}

/**
* Handle an error on the image
* Attempt to get an authorised version of the image
* When that fails, or no logo is present, show the placeholder
*/
errorHandler(event) {
event.currentTarget.src = this.holderSource;
console.log(event);

Check warning on line 45 in src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts#L45

Added line #L45 was not covered by tests
if (this.logo?._links?.content?.href) {
this.loading = true;
this.auth.isAuthenticated().pipe(

Check warning on line 48 in src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts#L47-L48

Added lines #L47 - L48 were not covered by tests
switchMap((isLoggedIn) => {
if (isLoggedIn) {
return this.authorizationService.isAuthorized(FeatureID.CanDownload, this.logo.self);

Check warning on line 51 in src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts#L51

Added line #L51 was not covered by tests
} else {
return observableOf(false);

Check warning on line 53 in src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts#L53

Added line #L53 was not covered by tests
}
}),
switchMap((isAuthorized) => {
if (isAuthorized) {
return this.fileService.retrieveFileDownloadLink(this.logo._links.content.href);

Check warning on line 58 in src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts#L58

Added line #L58 was not covered by tests
} else {
return observableOf(null);

Check warning on line 60 in src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts#L60

Added line #L60 was not covered by tests
}
}),
).subscribe((src) => {
if (hasValue(src)) {
event.target.src = src;

Check warning on line 65 in src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts#L65

Added line #L65 was not covered by tests
} else {
event.target.src = this.holderSource;

Check warning on line 67 in src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts#L67

Added line #L67 was not covered by tests
}
this.loading = false;

Check warning on line 69 in src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts#L69

Added line #L69 was not covered by tests
});
} else {
event.currentTarget.src = this.holderSource;

Check warning on line 72 in src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/comcol/comcol-page-logo/comcol-page-logo.component.ts#L72

Added line #L72 was not covered by tests
}
}

}
Loading