Skip to content
Merged
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
6 changes: 3 additions & 3 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@babylonjs/loaders": "9.0.0",
"@babylonjs/materials": "9.0.0",
"@babylonjs/serializers": "9.0.0",
"@kompakkt/common": "git+https://github.com/Kompakkt/Common#07dd559",
"@kompakkt/common": "git+https://github.com/Kompakkt/Common#802b2f0",
"@kompakkt/komponents": "git+https://github.com/Kompakkt/Komponents#6f91b0f",
"@kompakkt/plugins": "git+https://github.com/Kompakkt/Plugins#3ef7a55",
"bson-objectid": "^2.0.4",
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,4 @@ <h1>{{ 'Share Annotation to Collection' | translate }}</h1>
<k-button (click)="share()">{{ 'Share' | translate }}</k-button>
<k-button (click)="cancel()">{{ 'Cancel' | translate }}</k-button>
</k-button-row>

@if (checkPwdMode) {
<p>{{ 'The target collection is protected by a password.' | translate }}</p>
<p>{{ 'Enter the password to continue.' | translate }}</p>
}

<k-input
[label]="'Password' | translate"
type="password"
(valueChanged)="passwordCollection = $event.value"
/>

<k-button-row align="end">
<k-button (click)="cancel()">{{ 'Cancel' | translate }}</k-button>
<k-button (click)="checkPwd()">{{ 'Check' | translate }}</k-button>
</k-button-row>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import { TranslatePipe } from '../../../pipes/translate.pipe';
})
export class DialogShareAnnotationComponent {
public targetCollectionId = '';
public checkPwdMode = false;
public passwordCollection = '';
private entityId = '';
private response: any = {
private response: {
status: boolean;
collectionId: string;
annotationListLength: number;
} = {
status: false,
collectionId: '',
annotationListLength: 1,
Expand All @@ -40,12 +42,7 @@ export class DialogShareAnnotationComponent {
this.backend
.getCompilation(this.targetCollectionId)
.then(compilation => {
if (!compilation) {
// 'password'
this.checkPwdMode = true;
} else {
// collection is available on server
// loaded'
if (compilation) {
compilation = compilation as ICompilation;

if (!compilation.entities[this.entityId])
Expand Down Expand Up @@ -75,29 +72,4 @@ export class DialogShareAnnotationComponent {
console.log('canceled');
this.dialogRef.close(this.response);
}

public checkPwd() {
if (this.targetCollectionId !== '') {
this.backend
.getCompilation(this.targetCollectionId, this.passwordCollection)
.then(compilation => {
if (!compilation)
return this.message.error(
`Password is wrong for collection with ID ${this.targetCollectionId}`,
);
compilation = compilation as ICompilation;
this.response = {
status: true,
collectionId: this.targetCollectionId,
annotationListLength: Object.keys(compilation.annotations).length ?? 1,
};
this.dialogRef.close(this.response);
})
.catch(error => {
console.error(error);
this.message.error('Connection to entity server refused.');
this.dialogRef.close(this.response);
});
}
}
}
10 changes: 3 additions & 7 deletions src/app/services/backend/backend.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,10 @@ export class BackendService {
/**
* Fetch a resolved compilation by it's identifier
* @param {string} identifier Database _id of the compilation
* @param {string} password (Optional) Password of the compilation
* @param {[type]} [description]
* @return {Promise} Returns the compilation or null if it's password protected
* @return {Promise} Returns the compilation or null
*/
public async getCompilation(identifier: string, password?: string): Promise<ICompilation | null> {
return password
? this.get(`api/v1/get/find/compilation/${identifier}/${password}`)
: this.get(`api/v1/get/find/compilation/${identifier}`);
public async getCompilation(identifier: string): Promise<ICompilation | null> {
return this.get(`api/v1/get/find/compilation/${identifier}`);
}

public async getEntityMetadata(identifier: string): Promise<IDigitalEntity> {
Expand Down
114 changes: 53 additions & 61 deletions src/app/services/processing/processing.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
settingsKompakktLogo,
} from '../../../assets/settings/settings';
// tslint:disable-next-line:max-line-length
import { DialogPasswordComponent } from '../../components/dialogs/dialog-password/dialog-password.component';
import { decodeBase64, decodeURIUntilStable, isBase64 } from '../../helpers';
import { IIIFData, convertIIIFAnnotation, isIIIFData } from '../../helpers/iiif-data-helper';
import { BabylonService } from '../babylon/babylon.service';
Expand Down Expand Up @@ -273,7 +272,7 @@ export class ProcessingService {
this.babylon.resize();
}

public async updateActiveCompilation(compilation: ICompilation | undefined) {
public updateActiveCompilation(compilation: ICompilation | undefined) {
this.compilation$.next(compilation);
}

Expand Down Expand Up @@ -515,57 +514,62 @@ export class ProcessingService {
return this.loadEntity(fallbackEntity as IEntity, '');
}

public fetchAndLoad(entityId?: string | null, compilationId?: string | null) {
public async fetchAndLoad(entityId?: string | null, compilationId?: string | null) {
if (entityId && !compilationId) {
this.fetchEntityData(entityId);
return this.fetchEntityData(entityId);
}
if (compilationId) {
this.fetchCompilationData(compilationId, entityId ? entityId : undefined);
return this.fetchCompilationData(compilationId, entityId ? entityId : undefined);
}
}

private fetchCompilationData(id: string, specifiedEntity?: string, password?: string) {
this.backend
.getCompilation(id, password ?? undefined)
.then(compilation => {
if (compilation) {
this.updateActiveCompilation(compilation as ICompilation);
this.fetchEntityDataAfterCollection(compilation, specifiedEntity);
} else {
const dialogRef = this.dialog.open(DialogPasswordComponent, {
disableClose: true,
autoFocus: true,
data: { id },
});
dialogRef
.afterClosed()
.subscribe(({ result, data }: { result: boolean; data: ICompilation }) => {
if (result) {
this.updateActiveCompilation(data);
this.fetchEntityDataAfterCollection(data, specifiedEntity);
} else {
this.loadFallbackEntity();
this.message.error('Sorry, you are not allowed to load this Collection.');
}
});
private async fetchCompilationData(id: string, specifiedEntity?: string) {
return this.backend
.getCompilation(id)
.then(async compilation => {
if (!compilation) {
throw new Error('Compilation not found');
}

const isRestricted = typeof compilation.online === 'boolean' && !compilation.online;
if (isRestricted) {
const auth = await this.userdata.userAuthentication(true);
console.log('isRestricted auth check', auth, document);
if (!auth) {
this.message.error('You need to be logged in to access this collection.');
throw new Error('User authentication failed');
}
if (!this.userdata.doesUserOwn(compilation)) {
if (!this.userdata.doesUserHaveAccess(compilation)) {
this.message.error('Sorry, you are not allowed to load this collection.');
throw new Error('User does not have access to this compilation');
}
}
}

this.updateActiveCompilation(compilation as ICompilation);
return this.fetchEntityDataAfterCollection(compilation, specifiedEntity);
})
.catch(error => {
this.message.error('Error loading collection.');
console.error(error);
this.loadFallbackEntity();
return this.loadFallbackEntity();
});
}

private fetchEntityDataAfterCollection(compilation: ICompilation, specifiedEntity?: string) {
private async fetchEntityDataAfterCollection(
compilation: ICompilation,
specifiedEntity?: string,
) {
const specified = specifiedEntity && compilation.entities[specifiedEntity.toString()];
const entityToLoad = isEntity(specified) ? specified : Object.values(compilation.entities)[0];
if (isEntity(entityToLoad)) this.fetchEntityData(entityToLoad._id);
if (isEntity(entityToLoad)) return this.fetchEntityData(entityToLoad._id);
}

public fetchEntityData(query: string) {
this.backend
public async fetchEntityData(query: string) {
return this.backend
.getEntity(query)
.then(entity => {
.then(async entity => {
console.log('Received this Entity:', entity);

// Force load the entity via query parameter, skipping any checks below.
Expand Down Expand Up @@ -595,37 +599,25 @@ export class ProcessingService {
console.log('Are access to this entity restricted', isRestricted);

if (isRestricted) {
console.log(this.fetchRestrictedEntityData, 'f');
const auth = await this.userdata.userAuthentication(true);
console.log('isRestricted auth check', auth, document);
if (!auth) {
this.message.error('You need to be logged in to access this entity.');
throw new Error('User authentication failed');
}
if (!this.userdata.doesUserOwn(entity)) {
if (!this.userdata.doesUserHaveAccess(entity)) {
this.message.error('Sorry, you are not allowed to load this object.');
throw new Error('User does not have access to this entity');
}
}
}

this.loadEntity(entity);
return this.loadEntity(entity);
})
.catch(error => {
console.error(error);
this.loadFallbackEntity();
});
}

private async fetchRestrictedEntityData(entity: IEntity) {
this.userdata
.userAuthentication(true)
.then(auth => {
console.log('fetchRestrictedEntityData', auth, entity);
// Check for user authentication
if (!auth) return false;
// Check for ownership
if (!this.userdata.doesUserOwn(entity)) {
if (!this.userdata.doesUserHaveAccess(entity)) return false;
}
return true;
})
.then(canUserAccess => {
if (canUserAccess) {
this.loadEntity(entity);
} else {
this.message.error('Sorry you are not allowed to load this object.');
this.loadFallbackEntity();
}
return this.loadFallbackEntity();
});
}

Expand Down
Loading