-
Notifications
You must be signed in to change notification settings - Fork 13
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
patron: allows librarians to update user password #411
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Remove
console.log
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.
I think that it is to leave at is as it is displayed only when an error occurs. This can be useful. But if you want I can remove it.