-
Notifications
You must be signed in to change notification settings - Fork 6
fix(organsation): add the organisation to a new project #446
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,7 +96,7 @@ | |
| ]; | ||
| const fileConfig = { | ||
| enabled: true, | ||
| orderList: (a: any, b: any) => { | ||
|
Check warning on line 99 in projects/sonar/src/app/app-routing.module.ts
|
||
| return a.metadata.order - b.metadata.order; | ||
| }, | ||
| infoExcludedFields: [ | ||
|
|
@@ -107,7 +107,7 @@ | |
| 'permissions', | ||
| ], | ||
| canAdd: () => of({ can: true, message: '' }), | ||
| canRead: (record: any, file: any) => { | ||
|
Check warning on line 110 in projects/sonar/src/app/app-routing.module.ts
|
||
| if (file && file?.metadata?.permissions?.read) { | ||
| return of({ | ||
| can: file.metadata.permissions.read, | ||
|
|
@@ -116,7 +116,7 @@ | |
| } | ||
| return of({ can: false, message: '' }); | ||
| }, | ||
| canUpdateMetadata: (record: any, file: any) => { | ||
|
Check warning on line 119 in projects/sonar/src/app/app-routing.module.ts
|
||
| if (file && file?.metadata?.permissions?.update) { | ||
| return of({ | ||
| can: file.metadata.permissions.update, | ||
|
|
@@ -156,7 +156,7 @@ | |
| export class AppRoutingModule { | ||
|
|
||
| private translateService: TranslateService = inject(TranslateService); | ||
| private router: Router= inject(Router); | ||
| private router: Router = inject(Router); | ||
| private route: ActivatedRoute = inject(ActivatedRoute); | ||
| private userService: UserService = inject(UserService); | ||
| private httpClient: HttpClient = inject(HttpClient); | ||
|
|
@@ -279,7 +279,8 @@ | |
| Accept: 'application/rero+json' | ||
| } | ||
| }, | ||
| files: {...fileConfig, | ||
| files: { | ||
| ...fileConfig, | ||
| filterList: (item: any) => { | ||
| return ( | ||
| item.metadata && | ||
|
|
@@ -396,6 +397,29 @@ | |
| editorSettings: { | ||
| longMode: true, | ||
| }, | ||
| preCreateRecord: (record: any) => { | ||
| const user = this.userService.currentUser(); | ||
| // add organisation reference to the new record | ||
| const organisationCode = user.organisation.code; | ||
| if (organisationCode) { | ||
| record.metadata.organisation = { | ||
| $ref: this.apiService.getRefEndpoint( | ||
| 'organisations', | ||
| organisationCode | ||
| ) | ||
| }; | ||
| } | ||
| const userPid = user.pid; | ||
| if (userPid) { | ||
| record.metadata.user = { | ||
| $ref: this.apiService.getRefEndpoint( | ||
| 'users', | ||
| userPid | ||
| ) | ||
| }; | ||
| } | ||
| return record; | ||
| }, | ||
|
Comment on lines
+400
to
+422
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure The code assumes 🛡️ Proposed defensive fix preCreateRecord: (record: any) => {
// add organisation reference to the new record
const organisationCode = this.userService.getOrganisationCode();
if (organisationCode) {
+ record.metadata = record.metadata || {};
record.metadata.organisation = {
$ref: this.apiService.getRefEndpoint(
'organisations',
organisationCode
)
};
}
return record;
},🤖 Prompt for AI Agents |
||
| exportFormats: [ | ||
| { | ||
| label: 'CSV', | ||
|
|
@@ -474,8 +498,8 @@ | |
| if (user) { | ||
| /** Removes collections and subdivisions routes on the organisation shared */ | ||
| if (!('isDedicated' in user.organisation) || !(user.organisation.isDedicated)) { | ||
| recordsRoutesConfiguration = recordsRoutesConfiguration | ||
| .filter(route => !(['collections', 'subdivisions'].includes(route.type))); | ||
| recordsRoutesConfiguration = recordsRoutesConfiguration | ||
| .filter(route => !(['collections', 'subdivisions'].includes(route.type))); | ||
| } | ||
|
|
||
| recordsRoutesConfiguration.forEach((config: any) => { | ||
|
|
@@ -521,6 +545,7 @@ | |
| recordResource: config.recordResource || null, | ||
| exportFormats: config.exportFormats || null, | ||
| sortOptions: config.sortOptions || null, | ||
| preCreateRecord: config.preCreateRecord || null, | ||
| canAdd: () => this._can(config.type, 'add'), | ||
| canUpdate: (record: any) => this._can(config.type, 'update', record), | ||
| canDelete: (record: any) => this._can(config.type, 'delete', record), | ||
|
|
@@ -634,7 +659,7 @@ | |
| private _documentAggregationsOrder(): Observable<any> { | ||
| return of(null).pipe( | ||
| switchMap(() => { | ||
| const {view} = this.route.snapshot.children[0].params; | ||
| const { view } = this.route.snapshot.children[0].params; | ||
|
|
||
| let params = new HttpParams(); | ||
| if (view) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| <!-- | ||
| SONAR User Interface | ||
| Copyright (C) 2021 RERO | ||
|
|
||
| This program is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU Affero General Public License as published by | ||
| the Free Software Foundation, version 3 of the License. | ||
|
|
||
| This program is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU Affero General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU Affero General Public License | ||
| along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| --> | ||
| @if(validation && user && (isModerator() || isOwner())) { | ||
| <p-panel [header]="'Validation' | translate"> | ||
| <div class="ui:flex ui:flex-col ui:gap-2 ui:justify-center ui:p-2"> | ||
| @if(validation.status === validationStatus.IN_PROGRESS || validation.status === validationStatus.ASK_FOR_CHANGES) { | ||
| <p-message class="ui:w-full" severity="warn" showTransitionOptions="0ms"> | ||
| {{ "The record is currently in status \"\{\{ status \}\}\". It is not visible in public views." | translate: { status: (validation.status) | translate } }} | ||
| @if(isOwner()) { | ||
| <a href="#" class="alert-link" (click)="$event.preventDefault(); updateValidation(validationAction.PUBLISH)" translate> | ||
| Submit it | ||
| </a>. | ||
| } | ||
| </p-message> | ||
| } | ||
| @if(validation.status === validationStatus.TO_VALIDATE) { | ||
| <p-message class="ui:w-full" severity="warn" showTransitionOptions="0ms"> | ||
| {{"The record is in validation. It will be reviewed by a moderator before publishing." | translate}} | ||
| </p-message> | ||
| } | ||
| @if(validation.status === validationStatus.REJECTED) { | ||
| <p-message class="ui:w-full" severity="error" showTransitionOptions="0ms"> | ||
| {{ "The record has been rejected after a review from a moderator." | translate}} | ||
| </p-message> | ||
| } | ||
| @if(validation.status === validationStatus.VALIDATED) { | ||
| <p-message class="ui:w-full" severity="success" showTransitionOptions="0ms"> | ||
| {{ "The record is currently published. It is visible in public views." | translate }} | ||
| </p-message> | ||
|
|
||
| } | ||
| @if(validation.status === validationStatus.TO_VALIDATE && isModerator()) { | ||
| <textarea | ||
| #comment | ||
| class="ui:min-w-lg ui:my-4" | ||
| pTextarea | ||
| [autoResize]="true" | ||
| [placeholder]="'Leave a comment...' | translate" | ||
| ></textarea> | ||
| <div class="ui:flex ui:justify-center"> | ||
| <p-buttongroup class="ui:mx-auto"> | ||
| <p-button | ||
| size="large" | ||
| severity="success" | ||
| (onClick)="updateValidation(validationAction.APPROVE)" | ||
| [label]="'Approve' | translate" | ||
| /> | ||
| <p-button | ||
| size="large" | ||
| severity="warn" | ||
| (onClick)="updateValidation(validationAction.ASK_FOR_CHANGES)" | ||
| [label]="'Ask for changes' | translate" | ||
| /> | ||
| <p-button | ||
| size="large" | ||
| severity="danger" | ||
| (onClick)="updateValidation(validationAction.REJECT)" | ||
| [label]="'Reject' | translate" | ||
| /> | ||
| </p-buttongroup> | ||
| </div> | ||
| } | ||
| @if(validation.logs) { | ||
| <p-button | ||
| [text]="true" | ||
| [label]="(showLogs ? 'Hide logs' : 'Show logs') | translate" | ||
| (onClick)="showLogs = !showLogs" | ||
| /> | ||
| @if(showLogs) { | ||
| <p-table [value]="validation.logs" [tableStyle]="{ 'min-width': '50rem' }"> | ||
| <ng-template #header> | ||
| <tr> | ||
| <th translate>Status</th> | ||
| <th translate>Date</th> | ||
| <th translate>User</th> | ||
| <th translate>Comment</th> | ||
| </tr> | ||
| </ng-template> | ||
| <ng-template #body let-log> | ||
| <tr> | ||
| <td>{{ (log.status) | translate }}</td> | ||
| <td>{{ log.date | dateTranslate: 'medium' }}</td> | ||
| <td>{{ log.user.name }}</td> | ||
| <td [innerHtml]="log.comment | nl2br"></td> | ||
| </tr> | ||
| </ng-template> | ||
| </p-table> | ||
| } | ||
| } | ||
| </div> | ||
| </p-panel> | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard null
currentUser()/organisationbefore dereference.Line 403 assumes
useranduser.organisationare always present; ifcurrentUser()isn’t ready, this will throw. Consider optional chaining (and still initializerecord.metadataas per the earlier comment).Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents