Skip to content

Commit 075700a

Browse files
authored
Merge pull request DSpace#2725 from alexandrevryghem/w2p-109964_fix-vocabulary-options-with-url-as-stored-value_contribute-main
Encode all `RequestParam` values
2 parents 739af16 + babe936 commit 075700a

15 files changed

Lines changed: 43 additions & 82 deletions
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
21
/**
32
* Class representing a query parameter (query?fieldName=fieldValue) used in FindListOptions object
43
*/
54
export class RequestParam {
6-
constructor(public fieldName: string, public fieldValue: any) {
7-
5+
constructor(
6+
public fieldName: string,
7+
public fieldValue: any,
8+
public encodeValue = true,
9+
) {
10+
if (encodeValue) {
11+
this.fieldValue = encodeURIComponent(fieldValue);
12+
}
813
}
914
}

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

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -533,40 +533,18 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
533533
* @param arrayOfItemIds The uuid of the items to be found on the other side of returned relationships
534534
*/
535535
searchByItemsAndType(typeId: string,itemUuid: string,relationshipLabel: string, arrayOfItemIds: string[] ): Observable<RemoteData<PaginatedList<Relationship>>> {
536-
537-
const searchParams = [
538-
{
539-
fieldName: 'typeId',
540-
fieldValue: typeId,
541-
},
542-
{
543-
fieldName: 'focusItem',
544-
fieldValue: itemUuid,
545-
},
546-
{
547-
fieldName: 'relationshipLabel',
548-
fieldValue: relationshipLabel,
549-
},
550-
{
551-
fieldName: 'size',
552-
fieldValue: arrayOfItemIds.length,
553-
},
554-
{
555-
fieldName: 'embed',
556-
fieldValue: 'leftItem',
557-
},
558-
{
559-
fieldName: 'embed',
560-
fieldValue: 'rightItem',
561-
},
536+
const searchParams: RequestParam[] = [
537+
new RequestParam('typeId', typeId),
538+
new RequestParam('focusItem', itemUuid),
539+
new RequestParam('relationshipLabel', relationshipLabel),
540+
new RequestParam('size', arrayOfItemIds.length),
541+
new RequestParam('embed', 'leftItem'),
542+
new RequestParam('embed', 'rightItem'),
562543
];
563544

564545
arrayOfItemIds.forEach( (itemId) => {
565546
searchParams.push(
566-
{
567-
fieldName: 'relatedItem',
568-
fieldValue: itemId,
569-
},
547+
new RequestParam('relatedItem', itemId),
570548
);
571549
});
572550

src/app/core/data/relationship-type-data.service.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
FollowLinkConfig,
1717
} from '../../shared/utils/follow-link-config.model';
1818
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
19+
import { RequestParam } from '../cache/models/request-param.model';
1920
import { ObjectCacheService } from '../cache/object-cache.service';
2021
import { HALEndpointService } from '../shared/hal-endpoint.service';
2122
import { ItemType } from '../shared/item-relationships/item-type.model';
@@ -143,14 +144,8 @@ export class RelationshipTypeDataService extends BaseDataService<RelationshipTyp
143144
'byEntityType',
144145
{
145146
searchParams: [
146-
{
147-
fieldName: 'type',
148-
fieldValue: type,
149-
},
150-
{
151-
fieldName: 'size',
152-
fieldValue: 100,
153-
},
147+
new RequestParam('type', type),
148+
new RequestParam('size', 100),
154149
],
155150
}, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow,
156151
).pipe(

src/app/core/eperson/eperson-data.service.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,23 @@ describe('EPersonDataService', () => {
114114
it('search by default scope (byMetadata) and no query', () => {
115115
service.searchByScope(null, '');
116116
const options = Object.assign(new FindListOptions(), {
117-
searchParams: [Object.assign(new RequestParam('query', encodeURIComponent('')))],
117+
searchParams: [Object.assign(new RequestParam('query', ''))],
118118
});
119119
expect(service.searchBy).toHaveBeenCalledWith('byMetadata', options, true, true);
120120
});
121121

122122
it('search metadata scope and no query', () => {
123123
service.searchByScope('metadata', '');
124124
const options = Object.assign(new FindListOptions(), {
125-
searchParams: [Object.assign(new RequestParam('query', encodeURIComponent('')))],
125+
searchParams: [Object.assign(new RequestParam('query', ''))],
126126
});
127127
expect(service.searchBy).toHaveBeenCalledWith('byMetadata', options, true, true);
128128
});
129129

130130
it('search metadata scope and with query', () => {
131131
service.searchByScope('metadata', 'test');
132132
const options = Object.assign(new FindListOptions(), {
133-
searchParams: [Object.assign(new RequestParam('query', encodeURIComponent('test')))],
133+
searchParams: [Object.assign(new RequestParam('query', 'test'))],
134134
});
135135
expect(service.searchBy).toHaveBeenCalledWith('byMetadata', options, true, true);
136136
});
@@ -140,7 +140,7 @@ describe('EPersonDataService', () => {
140140
spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(null));
141141
service.searchByScope('email', '');
142142
const options = Object.assign(new FindListOptions(), {
143-
searchParams: [Object.assign(new RequestParam('email', encodeURIComponent('')))],
143+
searchParams: [Object.assign(new RequestParam('email', ''))],
144144
});
145145
expect((service as any).searchData.getSearchByHref).toHaveBeenCalledWith('byEmail', options);
146146
expect(service.findByHref).toHaveBeenCalledWith(epersonsEndpoint, true, true);
@@ -151,7 +151,7 @@ describe('EPersonDataService', () => {
151151
spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(EPersonMock));
152152
service.searchByScope('email', EPersonMock.email);
153153
const options = Object.assign(new FindListOptions(), {
154-
searchParams: [Object.assign(new RequestParam('email', encodeURIComponent(EPersonMock.email)))],
154+
searchParams: [Object.assign(new RequestParam('email', EPersonMock.email))],
155155
});
156156
expect((service as any).searchData.getSearchByHref).toHaveBeenCalledWith('byEmail', options);
157157
expect(service.findByHref).toHaveBeenCalledWith(epersonsEndpoint, true, true);

src/app/core/eperson/eperson-data.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export class EPersonDataService extends IdentifiableDataService<EPerson> impleme
163163
*/
164164
public getEPersonByEmail(query: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<EPerson>[]): Observable<RemoteData<EPerson | NoContent>> {
165165
const findListOptions = new FindListOptions();
166-
findListOptions.searchParams = [new RequestParam('email', encodeURIComponent(query))];
166+
findListOptions.searchParams = [new RequestParam('email', query)];
167167
const href$ = this.searchData.getSearchByHref(this.searchByEmailPath, findListOptions, ...linksToFollow);
168168
return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
169169
}
@@ -180,7 +180,7 @@ export class EPersonDataService extends IdentifiableDataService<EPerson> impleme
180180
* {@link HALLink}s should be automatically resolved
181181
*/
182182
private getEpeopleByMetadata(query: string, options?: FindListOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<EPerson>[]): Observable<RemoteData<PaginatedList<EPerson>>> {
183-
const searchParams = [new RequestParam('query', encodeURIComponent(query))];
183+
const searchParams = [new RequestParam('query', query)];
184184
return this.getEPeopleBy(searchParams, this.searchByMetadataPath, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
185185
}
186186

src/app/core/notifications/qa/events/quality-assurance-event-data.service.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { NotificationsService } from '../../../../shared/notifications/notificat
1616
import { createSuccessfulRemoteDataObject } from '../../../../shared/remote-data.utils';
1717
import { ObjectCacheServiceStub } from '../../../../shared/testing/object-cache-service.stub';
1818
import { RemoteDataBuildService } from '../../../cache/builders/remote-data-build.service';
19+
import { RequestParam } from '../../../cache/models/request-param.model';
1920
import { ObjectCacheService } from '../../../cache/object-cache.service';
2021
import { RestResponse } from '../../../cache/response.models';
2122
import { FindListOptions } from '../../../data/find-list-options.model';
@@ -131,10 +132,7 @@ describe('QualityAssuranceEventDataService', () => {
131132
it('should proxy the call to searchData.searchBy', () => {
132133
const options: FindListOptions = {
133134
searchParams: [
134-
{
135-
fieldName: 'topic',
136-
fieldValue: topic,
137-
},
135+
new RequestParam('topic', topic),
138136
],
139137
};
140138
service.getEventsByTopic(topic);

src/app/core/notifications/qa/events/quality-assurance-event-data.service.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { hasValue } from '../../../../shared/empty.util';
1616
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
1717
import { FollowLinkConfig } from '../../../../shared/utils/follow-link-config.model';
1818
import { RemoteDataBuildService } from '../../../cache/builders/remote-data-build.service';
19+
import { RequestParam } from '../../../cache/models/request-param.model';
1920
import { ObjectCacheService } from '../../../cache/object-cache.service';
2021
import {
2122
CreateData,
@@ -97,10 +98,7 @@ export class QualityAssuranceEventDataService extends IdentifiableDataService<Qu
9798
*/
9899
public getEventsByTopic(topic: string, options: FindListOptions = {}, ...linksToFollow: FollowLinkConfig<QualityAssuranceEventObject>[]): Observable<RemoteData<PaginatedList<QualityAssuranceEventObject>>> {
99100
options.searchParams = [
100-
{
101-
fieldName: 'topic',
102-
fieldValue: topic,
103-
},
101+
new RequestParam('topic', topic),
104102
];
105103
return this.searchData.searchBy('findByTopic', options, true, true, ...linksToFollow);
106104
}

src/app/core/statistics/usage-report-data.service.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { map } from 'rxjs/operators';
44

55
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
66
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
7+
import { RequestParam } from '../cache/models/request-param.model';
78
import { ObjectCacheService } from '../cache/object-cache.service';
89
import { IdentifiableDataService } from '../data/base/identifiable-data.service';
910
import {
@@ -49,10 +50,7 @@ export class UsageReportDataService extends IdentifiableDataService<UsageReport>
4950
searchStatistics(uri: string, page: number, size: number): Observable<UsageReport[]> {
5051
return this.searchBy('object', {
5152
searchParams: [
52-
{
53-
fieldName: `uri`,
54-
fieldValue: uri,
55-
},
53+
new RequestParam('uri', uri),
5654
],
5755
currentPage: page,
5856
elementsPerPage: size,

src/app/core/submission/correctiontype-data.service.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ export class CorrectionTypeDataService extends IdentifiableDataService<Correctio
7676
findByTopic(topic: string, useCachedVersionIfAvailable = true, reRequestOnStale = true): Observable<CorrectionType> {
7777
const options = new FindListOptions();
7878
options.searchParams = [
79-
{
80-
fieldName: 'topic',
81-
fieldValue: topic,
82-
},
79+
new RequestParam('topic', topic),
8380
];
8481

8582
return this.searchData.searchBy(this.searchByTopic, options, useCachedVersionIfAvailable, reRequestOnStale).pipe(

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77

88
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
99
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
10+
import { RequestParam } from '../cache/models/request-param.model';
1011
import { ObjectCacheService } from '../cache/object-cache.service';
1112
import { BaseDataService } from '../data/base/base-data.service';
1213
import {
@@ -54,17 +55,8 @@ export class SubmissionCcLicenseUrlDataService extends BaseDataService<Submissio
5455
return this.searchData.getSearchByHref(
5556
'rightsByQuestions',{
5657
searchParams: [
57-
{
58-
fieldName: 'license',
59-
fieldValue: ccLicense.id,
60-
},
61-
...ccLicense.fields.map(
62-
(field) => {
63-
return {
64-
fieldName: `answer_${field.id}`,
65-
fieldValue: options.get(field).id,
66-
};
67-
}),
58+
new RequestParam('license', ccLicense.id),
59+
...ccLicense.fields.map((field: Field) => new RequestParam(`answer_${field.id}`, options.get(field).id)),
6860
],
6961
},
7062
).pipe(

0 commit comments

Comments
 (0)