Skip to content

Commit abe5258

Browse files
committed
fix(organsation): add the organisation to a new project
* Adds the current user organisation information when a new project is created. * Adds a new method to return the current user organisation to the user service. Co-Authored-by: Johnny Mariéthoz <Johnny.Mariethoz@rero.ch>
1 parent ab66357 commit abe5258

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

projects/sonar/src/app/app-routing.module.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export const typeResolver: ResolveFn<string> = (route) => {
156156
export class AppRoutingModule {
157157

158158
private translateService: TranslateService = inject(TranslateService);
159-
private router: Router= inject(Router);
159+
private router: Router = inject(Router);
160160
private route: ActivatedRoute = inject(ActivatedRoute);
161161
private userService: UserService = inject(UserService);
162162
private httpClient: HttpClient = inject(HttpClient);
@@ -279,7 +279,8 @@ export class AppRoutingModule {
279279
Accept: 'application/rero+json'
280280
}
281281
},
282-
files: {...fileConfig,
282+
files: {
283+
...fileConfig,
283284
filterList: (item: any) => {
284285
return (
285286
item.metadata &&
@@ -396,6 +397,29 @@ export class AppRoutingModule {
396397
editorSettings: {
397398
longMode: true,
398399
},
400+
preCreateRecord: (record: any) => {
401+
const user = this.userService.currentUser();
402+
// add organisation reference to the new record
403+
const organisationCode = user.organisation.code;
404+
if (organisationCode) {
405+
record.metadata.organisation = {
406+
$ref: this.apiService.getRefEndpoint(
407+
'organisations',
408+
organisationCode
409+
)
410+
};
411+
}
412+
const userPid = user.pid;
413+
if (userPid) {
414+
record.metadata.user = {
415+
$ref: this.apiService.getRefEndpoint(
416+
'users',
417+
userPid
418+
)
419+
};
420+
}
421+
return record;
422+
},
399423
exportFormats: [
400424
{
401425
label: 'CSV',
@@ -474,8 +498,8 @@ export class AppRoutingModule {
474498
if (user) {
475499
/** Removes collections and subdivisions routes on the organisation shared */
476500
if (!('isDedicated' in user.organisation) || !(user.organisation.isDedicated)) {
477-
recordsRoutesConfiguration = recordsRoutesConfiguration
478-
.filter(route => !(['collections', 'subdivisions'].includes(route.type)));
501+
recordsRoutesConfiguration = recordsRoutesConfiguration
502+
.filter(route => !(['collections', 'subdivisions'].includes(route.type)));
479503
}
480504

481505
recordsRoutesConfiguration.forEach((config: any) => {
@@ -521,6 +545,7 @@ export class AppRoutingModule {
521545
recordResource: config.recordResource || null,
522546
exportFormats: config.exportFormats || null,
523547
sortOptions: config.sortOptions || null,
548+
preCreateRecord: config.preCreateRecord || null,
524549
canAdd: () => this._can(config.type, 'add'),
525550
canUpdate: (record: any) => this._can(config.type, 'update', record),
526551
canDelete: (record: any) => this._can(config.type, 'delete', record),
@@ -634,7 +659,7 @@ export class AppRoutingModule {
634659
private _documentAggregationsOrder(): Observable<any> {
635660
return of(null).pipe(
636661
switchMap(() => {
637-
const {view} = this.route.snapshot.children[0].params;
662+
const { view } = this.route.snapshot.children[0].params;
638663

639664
let params = new HttpParams();
640665
if (view) {

projects/sonar/src/app/user.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ export class UserService {
135135
&& this._user.organisation.isDedicated;
136136
}
137137

138+
currentUser(): any {
139+
return this._user;
140+
}
141+
138142
/**
139143
* Return the link to public interface, depending on user's organisation.
140144
* @returns Link to public interface.

0 commit comments

Comments
 (0)