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

[Port dspace-7_x] Encode all RequestParam values #3032

Merged
merged 1 commit into from
May 10, 2024
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
11 changes: 8 additions & 3 deletions src/app/core/cache/models/request-param.model.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@

/**
* Class representing a query parameter (query?fieldName=fieldValue) used in FindListOptions object
*/
export class RequestParam {
constructor(public fieldName: string, public fieldValue: any) {

constructor(
public fieldName: string,
public fieldValue: any,
public encodeValue = true,
) {
if (encodeValue) {
this.fieldValue = encodeURIComponent(fieldValue);
}
}
}
40 changes: 9 additions & 31 deletions src/app/core/data/relationship-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,40 +492,18 @@
* @param arrayOfItemIds The uuid of the items to be found on the other side of returned relationships
*/
searchByItemsAndType(typeId: string,itemUuid: string,relationshipLabel: string, arrayOfItemIds: string[] ): Observable<RemoteData<PaginatedList<Relationship>>> {

const searchParams = [
{
fieldName: 'typeId',
fieldValue: typeId
},
{
fieldName: 'focusItem',
fieldValue: itemUuid
},
{
fieldName: 'relationshipLabel',
fieldValue: relationshipLabel
},
{
fieldName: 'size',
fieldValue: arrayOfItemIds.length
},
{
fieldName: 'embed',
fieldValue: 'leftItem'
},
{
fieldName: 'embed',
fieldValue: 'rightItem'
},
];
const searchParams: RequestParam[] = [

Check warning on line 495 in src/app/core/data/relationship-data.service.ts

View check run for this annotation

Codecov / codecov/patch

src/app/core/data/relationship-data.service.ts#L495

Added line #L495 was not covered by tests
new RequestParam('typeId', typeId),
new RequestParam('focusItem', itemUuid),
new RequestParam('relationshipLabel', relationshipLabel),
new RequestParam('size', arrayOfItemIds.length),
new RequestParam('embed', 'leftItem'),
new RequestParam('embed', 'rightItem'),
];

arrayOfItemIds.forEach( (itemId) => {
searchParams.push(
{
fieldName: 'relatedItem',
fieldValue: itemId,
}
new RequestParam('relatedItem', itemId),
);
});

Expand Down
11 changes: 3 additions & 8 deletions src/app/core/data/relationship-type-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { FindAllDataImpl } from './base/find-all-data';
import { SearchDataImpl } from './base/search-data';
import { ObjectCacheService } from '../cache/object-cache.service';
import { dataService } from './base/data-service.decorator';
import { RequestParam } from '../cache/models/request-param.model';

/**
* Check if one side of a RelationshipType is the ItemType with the given label
Expand Down Expand Up @@ -130,14 +131,8 @@ export class RelationshipTypeDataService extends BaseDataService<RelationshipTyp
'byEntityType',
{
searchParams: [
{
fieldName: 'type',
fieldValue: type,
},
{
fieldName: 'size',
fieldValue: 100,
},
new RequestParam('type', type),
new RequestParam('size', 100),
],
}, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow,
).pipe(
Expand Down
10 changes: 5 additions & 5 deletions src/app/core/eperson/eperson-data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,23 @@ describe('EPersonDataService', () => {
it('search by default scope (byMetadata) and no query', () => {
service.searchByScope(null, '');
const options = Object.assign(new FindListOptions(), {
searchParams: [Object.assign(new RequestParam('query', encodeURIComponent('')))]
searchParams: [Object.assign(new RequestParam('query', ''))],
});
expect(service.searchBy).toHaveBeenCalledWith('byMetadata', options, true, true);
});

it('search metadata scope and no query', () => {
service.searchByScope('metadata', '');
const options = Object.assign(new FindListOptions(), {
searchParams: [Object.assign(new RequestParam('query', encodeURIComponent('')))]
searchParams: [Object.assign(new RequestParam('query', ''))],
});
expect(service.searchBy).toHaveBeenCalledWith('byMetadata', options, true, true);
});

it('search metadata scope and with query', () => {
service.searchByScope('metadata', 'test');
const options = Object.assign(new FindListOptions(), {
searchParams: [Object.assign(new RequestParam('query', encodeURIComponent('test')))]
searchParams: [Object.assign(new RequestParam('query', 'test'))],
});
expect(service.searchBy).toHaveBeenCalledWith('byMetadata', options, true, true);
});
Expand All @@ -123,7 +123,7 @@ describe('EPersonDataService', () => {
spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(null));
service.searchByScope('email', '');
const options = Object.assign(new FindListOptions(), {
searchParams: [Object.assign(new RequestParam('email', encodeURIComponent('')))]
searchParams: [Object.assign(new RequestParam('email', ''))],
});
expect((service as any).searchData.getSearchByHref).toHaveBeenCalledWith('byEmail', options);
expect(service.findByHref).toHaveBeenCalledWith(epersonsEndpoint, true, true);
Expand All @@ -134,7 +134,7 @@ describe('EPersonDataService', () => {
spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(EPersonMock));
service.searchByScope('email', EPersonMock.email);
const options = Object.assign(new FindListOptions(), {
searchParams: [Object.assign(new RequestParam('email', encodeURIComponent(EPersonMock.email)))]
searchParams: [Object.assign(new RequestParam('email', EPersonMock.email))],
});
expect((service as any).searchData.getSearchByHref).toHaveBeenCalledWith('byEmail', options);
expect(service.findByHref).toHaveBeenCalledWith(epersonsEndpoint, true, true);
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/eperson/eperson-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class EPersonDataService extends IdentifiableDataService<EPerson> impleme
*/
public getEPersonByEmail(query: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<EPerson>[]): Observable<RemoteData<EPerson | NoContent>> {
const findListOptions = new FindListOptions();
findListOptions.searchParams = [new RequestParam('email', encodeURIComponent(query))];
findListOptions.searchParams = [new RequestParam('email', query)];
const href$ = this.searchData.getSearchByHref(this.searchByEmailPath, findListOptions, ...linksToFollow);
return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
Expand All @@ -148,7 +148,7 @@ export class EPersonDataService extends IdentifiableDataService<EPerson> impleme
* {@link HALLink}s should be automatically resolved
*/
private getEpeopleByMetadata(query: string, options?: FindListOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<EPerson>[]): Observable<RemoteData<PaginatedList<EPerson>>> {
const searchParams = [new RequestParam('query', encodeURIComponent(query))];
const searchParams = [new RequestParam('query', query)];
return this.getEPeopleBy(searchParams, this.searchByMetadataPath, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}

Expand Down
6 changes: 2 additions & 4 deletions src/app/core/statistics/usage-report-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
import { RemoteData } from '../data/remote-data';
import { PaginatedList } from '../data/paginated-list.model';
import { dataService } from '../data/base/data-service.decorator';
import { RequestParam } from '../cache/models/request-param.model';

/**
* A service to retrieve {@link UsageReport}s from the REST API
Expand Down Expand Up @@ -45,10 +46,7 @@ export class UsageReportDataService extends IdentifiableDataService<UsageReport>
searchStatistics(uri: string, page: number, size: number): Observable<UsageReport[]> {
return this.searchBy('object', {
searchParams: [
{
fieldName: `uri`,
fieldValue: uri,
},
new RequestParam('uri', uri),
],
currentPage: page,
elementsPerPage: size,
Expand Down
14 changes: 3 additions & 11 deletions src/app/core/submission/submission-cc-license-url-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import { RemoteData } from '../data/remote-data';
import { PaginatedList } from '../data/paginated-list.model';
import { dataService } from '../data/base/data-service.decorator';
import { RequestParam } from '../cache/models/request-param.model';

@Injectable()
@dataService(SUBMISSION_CC_LICENSE_URL)
Expand Down Expand Up @@ -43,17 +44,8 @@
return this.searchData.getSearchByHref(
'rightsByQuestions',{
searchParams: [
{
fieldName: 'license',
fieldValue: ccLicense.id
},
...ccLicense.fields.map(
(field) => {
return {
fieldName: `answer_${field.id}`,
fieldValue: options.get(field).id,
};
}),
new RequestParam('license', ccLicense.id),
...ccLicense.fields.map((field: Field) => new RequestParam(`answer_${field.id}`, options.get(field).id)),

Check warning on line 48 in src/app/core/submission/submission-cc-license-url-data.service.ts

View check run for this annotation

Codecov / codecov/patch

src/app/core/submission/submission-cc-license-url-data.service.ts#L48

Added line #L48 was not covered by tests
]
}
).pipe(
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/submission/workflowitem-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class WorkflowItemDataService extends IdentifiableDataService<WorkflowIte
*/
public findByItem(uuid: string, useCachedVersionIfAvailable = false, reRequestOnStale = true, options: FindListOptions = {}, ...linksToFollow: FollowLinkConfig<WorkspaceItem>[]): Observable<RemoteData<WorkspaceItem>> {
const findListOptions = new FindListOptions();
findListOptions.searchParams = [new RequestParam('uuid', encodeURIComponent(uuid))];
findListOptions.searchParams = [new RequestParam('uuid', uuid)];
const href$ = this.searchData.getSearchByHref(this.searchByItemLinkPath, findListOptions, ...linksToFollow);
return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/submission/workspaceitem-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class WorkspaceitemDataService extends IdentifiableDataService<WorkspaceI
*/
public findByItem(uuid: string, useCachedVersionIfAvailable = false, reRequestOnStale = true, options: FindListOptions = {}, ...linksToFollow: FollowLinkConfig<WorkspaceItem>[]): Observable<RemoteData<WorkspaceItem>> {
const findListOptions = new FindListOptions();
findListOptions.searchParams = [new RequestParam('uuid', encodeURIComponent(uuid))];
findListOptions.searchParams = [new RequestParam('uuid', uuid)];
const href$ = this.getSearchByHref(this.searchByItemLinkPath, findListOptions, ...linksToFollow);
return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
Expand Down
Loading