-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patron: a professional can change a user password
* Adds missing license in some files. * Fixes some spelling. * Adds a button in the circulation patron profile to update the password. * Adds a edit button in the circulation patron profile. * Moves roles in the patron informations in the patron circulation profile and the patron detail view. Co-Authored-by: Johnny Mariéthoz <Johnny.Mariethoz@rero.ch>
- Loading branch information
Showing
11 changed files
with
396 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...admin/src/app/circulation/patron/change-password-form/change-password-form.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!-- | ||
RERO ILS UI | ||
Copyright (C) 2020 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/>. | ||
--> | ||
<div *ngIf="form" class="modal show d-block" role="dialog"> | ||
<div class="modal-dialog modal-dialog-centered" role="document"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h5 class="modal-title" translate>Update Patron Password</h5> | ||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||
<span aria-hidden="true" data-dismiss="modal" (click)="closeModal()">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
<form [formGroup]="form" (ngSubmit)="submit(patron, model)"> | ||
<formly-form [form]="form" [fields]="formFields" [model]="model"></formly-form> | ||
<div class="text-right"> | ||
<button id="change-password-submit-button" class="btn btn-primary" [disabled]="!form.valid" translate>Submit</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
53 changes: 53 additions & 0 deletions
53
...in/src/app/circulation/patron/change-password-form/change-password-form.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* RERO ILS UI | ||
* Copyright (C) 2020 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/>. | ||
*/ | ||
|
||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { BsModalRef } from 'ngx-bootstrap/modal'; | ||
import { CirculationModule } from '../../circulation.module'; | ||
import { ChangePasswordFormComponent } from './change-password-form.component'; | ||
|
||
|
||
describe('ChangePasswordFormComponent', () => { | ||
let component: ChangePasswordFormComponent; | ||
let fixture: ComponentFixture<ChangePasswordFormComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
TranslateModule.forRoot(), | ||
HttpClientTestingModule, | ||
CirculationModule | ||
], | ||
providers: [ | ||
BsModalRef | ||
] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ChangePasswordFormComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
136 changes: 136 additions & 0 deletions
136
...s/admin/src/app/circulation/patron/change-password-form/change-password-form.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* RERO ILS UI | ||
* Copyright (C) 2020 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/>. | ||
*/ | ||
|
||
import { Component, OnInit } from '@angular/core'; | ||
import { FormGroup } from '@angular/forms'; | ||
import { FormlyFieldConfig } from '@ngx-formly/core'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; | ||
import { ToastrService } from 'ngx-toastr'; | ||
import { User } from '../../../class/user'; | ||
import { UserService } from '../../../service/user.service'; | ||
|
||
@Component({ | ||
selector: 'admin-change-password-form', | ||
templateUrl: './change-password-form.component.html' | ||
}) | ||
export class ChangePasswordFormComponent implements OnInit { | ||
|
||
/** patron to change the password */ | ||
patron: User; | ||
|
||
/** form */ | ||
form: FormGroup = new FormGroup({}); | ||
|
||
/** model */ | ||
model = {}; | ||
|
||
/** form fields */ | ||
formFields: FormlyFieldConfig[]; | ||
|
||
/** | ||
* Constructor | ||
* @param _modalService - BsModalService | ||
* @param _bsModalRef - BsModalRef | ||
* @param _translateService - TranslateService | ||
* @param _toastr - ToastrService | ||
* @param _userService - UserService | ||
*/ | ||
constructor( | ||
private _modalService: BsModalService, | ||
private _bsModalRef: BsModalRef, | ||
private _translateService: TranslateService, | ||
private _toastr: ToastrService, | ||
private _userService: UserService | ||
) { } | ||
|
||
/** | ||
* Component initialization. | ||
*/ | ||
ngOnInit() { | ||
const initialState: any = this._modalService.config.initialState; | ||
if (initialState.hasOwnProperty('patron')) { | ||
this.closeModal(); | ||
} | ||
this.patron = initialState.patron; | ||
this._initForm(); | ||
} | ||
|
||
/** | ||
* Submit form | ||
* @param model - Object | ||
*/ | ||
submit(patron, model) { | ||
this._userService.changePassword(patron.username, model.password).subscribe( | ||
() => { | ||
this._toastr.success( | ||
this._translateService.instant('The patron password has been changed.'), | ||
); | ||
this.closeModal(); | ||
}, | ||
(resp) => { | ||
console.log('Error: Update Patron Password', resp); | ||
let error = this._translateService.instant('An error has occurred.'); | ||
if (resp.error && resp.error.message) { | ||
error = `${error}: (${resp.error.message})`; | ||
} | ||
this._toastr.error( | ||
error, | ||
this._translateService.instant('Update Patron Password'), | ||
{ disableTimeOut: true } | ||
); | ||
this.closeModal(); | ||
} | ||
); | ||
} | ||
|
||
/** | ||
* Initialize formly form. | ||
*/ | ||
private _initForm() { | ||
if (this.patron) { | ||
this.formFields = [ | ||
{ | ||
key: 'password', | ||
type: 'input', | ||
focus: true, | ||
templateOptions: { | ||
type: 'password', | ||
label: this._translateService.instant('New password'), | ||
required: true, | ||
// same as Invenio | ||
minLength: 6, | ||
maxLength: 128, | ||
keydown: (field, event) => { | ||
if (event.key === 'Enter') { | ||
event.preventDefault(); | ||
} | ||
} | ||
} | ||
} | ||
]; | ||
} | ||
} | ||
|
||
/** | ||
* Close modal dialog | ||
* @param event - Event | ||
*/ | ||
closeModal() { | ||
this._bsModalRef.hide(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...n-transactions/patron-transaction-event-form/patron-transaction-event-form.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...s/admin/src/app/circulation/patron/patron-transactions/patron-transactions.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.