@@ -156,7 +156,7 @@ export const typeResolver: ResolveFn<string> = (route) => {
156156export 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 ) {
0 commit comments