mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Hide internal data by making it auxiliary
This commit is contained in:
@@ -10,11 +10,11 @@ import type { AuxiliaryIdentifierStrategy } from './AuxiliaryIdentifierStrategy'
|
||||
*/
|
||||
export interface AuxiliaryStrategy extends AuxiliaryIdentifierStrategy {
|
||||
/**
|
||||
* Whether this auxiliary resource in a root storage container.
|
||||
* Whether the root storage container requires this auxiliary resource to be present.
|
||||
* If yes, this means they can't be deleted individually from such a container.
|
||||
* @param identifier - Identifier of the auxiliary resource.
|
||||
*/
|
||||
isRootRequired: (identifier: ResourceIdentifier) => boolean;
|
||||
isRequiredInRoot: (identifier: ResourceIdentifier) => boolean;
|
||||
|
||||
/**
|
||||
* Adds metadata related to this auxiliary resource,
|
||||
|
||||
@@ -14,14 +14,14 @@ export class ComposedAuxiliaryStrategy implements AuxiliaryStrategy {
|
||||
private readonly identifierStrategy: AuxiliaryIdentifierStrategy;
|
||||
private readonly metadataGenerator?: MetadataGenerator;
|
||||
private readonly validator?: Validator;
|
||||
private readonly rootRequired: boolean;
|
||||
private readonly requiredInRoot: boolean;
|
||||
|
||||
public constructor(identifierStrategy: AuxiliaryIdentifierStrategy, metadataGenerator?: MetadataGenerator,
|
||||
validator?: Validator, isRootRequired = false) {
|
||||
validator?: Validator, requiredInRoot = false) {
|
||||
this.identifierStrategy = identifierStrategy;
|
||||
this.metadataGenerator = metadataGenerator;
|
||||
this.validator = validator;
|
||||
this.rootRequired = isRootRequired;
|
||||
this.requiredInRoot = requiredInRoot;
|
||||
}
|
||||
|
||||
public getAuxiliaryIdentifier(identifier: ResourceIdentifier): ResourceIdentifier {
|
||||
@@ -40,8 +40,8 @@ export class ComposedAuxiliaryStrategy implements AuxiliaryStrategy {
|
||||
return this.identifierStrategy.getAssociatedIdentifier(identifier);
|
||||
}
|
||||
|
||||
public isRootRequired(): boolean {
|
||||
return this.rootRequired;
|
||||
public isRequiredInRoot(): boolean {
|
||||
return this.requiredInRoot;
|
||||
}
|
||||
|
||||
public async addMetadata(metadata: RepresentationMetadata): Promise<void> {
|
||||
|
||||
@@ -18,9 +18,9 @@ export class RoutingAuxiliaryStrategy extends RoutingAuxiliaryIdentifierStrategy
|
||||
super(sources);
|
||||
}
|
||||
|
||||
public isRootRequired(identifier: ResourceIdentifier): boolean {
|
||||
public isRequiredInRoot(identifier: ResourceIdentifier): boolean {
|
||||
const source = this.getMatchingSource(identifier);
|
||||
return source.isRootRequired(identifier);
|
||||
return source.isRequiredInRoot(identifier);
|
||||
}
|
||||
|
||||
public async addMetadata(metadata: RepresentationMetadata): Promise<void> {
|
||||
|
||||
@@ -235,7 +235,8 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
if (this.isRootStorage(metadata)) {
|
||||
throw new MethodNotAllowedHttpError('Cannot delete a root storage container.');
|
||||
}
|
||||
if (this.auxiliaryStrategy.isAuxiliaryIdentifier(identifier) && this.auxiliaryStrategy.isRootRequired(identifier)) {
|
||||
if (this.auxiliaryStrategy.isAuxiliaryIdentifier(identifier) &&
|
||||
this.auxiliaryStrategy.isRequiredInRoot(identifier)) {
|
||||
const associatedIdentifier = this.auxiliaryStrategy.getAssociatedIdentifier(identifier);
|
||||
const parentMetadata = await this.accessor.getMetadata(associatedIdentifier);
|
||||
if (this.isRootStorage(parentMetadata)) {
|
||||
|
||||
Reference in New Issue
Block a user