diff --git a/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.html b/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.html
index 45326c1abc..41ae67423c 100644
--- a/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.html
+++ b/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.html
@@ -19,7 +19,7 @@
class="btn btn-outline-secondary"> {{messagePrefix + '.return' | translate}}
-
@@ -36,9 +36,13 @@
+
+
{{messagePrefix + '.groupsEPersonIsMemberOf' | translate}}
+
+
0"
[paginationOptions]="config"
diff --git a/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts b/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts
index 1f4a106bfa..644b893265 100644
--- a/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts
+++ b/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts
@@ -2,7 +2,7 @@ import { Observable, of as observableOf } from 'rxjs';
import { CommonModule } from '@angular/common';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
-import { FormsModule, ReactiveFormsModule } from '@angular/forms';
+import { FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
import { BrowserModule, By } from '@angular/platform-browser';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
@@ -14,6 +14,7 @@ import { EPerson } from '../../../core/eperson/models/eperson.model';
import { PageInfo } from '../../../core/shared/page-info.model';
import { FormBuilderService } from '../../../shared/form/builder/form-builder.service';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
+import { EPeopleRegistryComponent } from '../epeople-registry.component';
import { EPersonFormComponent } from './eperson-form.component';
import { EPersonMock, EPersonMock2 } from '../../../shared/testing/eperson.mock';
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
@@ -28,9 +29,8 @@ import { createPaginatedList } from '../../../shared/testing/utils.test';
import { RequestService } from '../../../core/data/request.service';
import { PaginationService } from '../../../core/pagination/pagination.service';
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
-import { FormArray, FormControl, FormGroup,Validators, NG_VALIDATORS, NG_ASYNC_VALIDATORS } from '@angular/forms';
import { ValidateEmailNotTaken } from './validators/email-taken.validator';
-
+import { EpersonRegistrationService } from '../../../core/data/eperson-registration.service';
describe('EPersonFormComponent', () => {
let component: EPersonFormComponent;
@@ -42,6 +42,7 @@ describe('EPersonFormComponent', () => {
let authService: AuthServiceStub;
let authorizationService: AuthorizationDataService;
let groupsDataService: GroupDataService;
+ let epersonRegistrationService: EpersonRegistrationService;
let paginationService;
@@ -199,12 +200,18 @@ describe('EPersonFormComponent', () => {
{ provide: AuthService, useValue: authService },
{ provide: AuthorizationDataService, useValue: authorizationService },
{ provide: PaginationService, useValue: paginationService },
- { provide: RequestService, useValue: jasmine.createSpyObj('requestService', ['removeByHrefSubstring']) }
+ { provide: RequestService, useValue: jasmine.createSpyObj('requestService', ['removeByHrefSubstring'])},
+ { provide: EpersonRegistrationService, useValue: epersonRegistrationService },
+ EPeopleRegistryComponent
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
+ epersonRegistrationService = jasmine.createSpyObj('epersonRegistrationService', {
+ registerEmail: createSuccessfulRemoteDataObject$(null)
+ });
+
beforeEach(() => {
fixture = TestBed.createComponent(EPersonFormComponent);
component = fixture.componentInstance;
@@ -514,4 +521,23 @@ describe('EPersonFormComponent', () => {
expect(component.epersonService.deleteEPerson).toHaveBeenCalledWith(eperson);
});
});
+
+ describe('Reset Password', () => {
+ let ePersonId;
+ let ePersonEmail;
+
+ beforeEach(() => {
+ ePersonId = 'testEPersonId';
+ ePersonEmail = 'person.email@4science.it';
+ component.epersonInitial = Object.assign(new EPerson(), {
+ id: ePersonId,
+ email: ePersonEmail
+ });
+ component.resetPassword();
+ });
+
+ it('should call epersonRegistrationService.registerEmail', () => {
+ expect(epersonRegistrationService.registerEmail).toHaveBeenCalledWith(ePersonEmail);
+ });
+ });
});
diff --git a/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.ts b/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.ts
index 723939df77..05fc3189d0 100644
--- a/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.ts
+++ b/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.ts
@@ -34,6 +34,8 @@ import { NoContent } from '../../../core/shared/NoContent.model';
import { PaginationService } from '../../../core/pagination/pagination.service';
import { followLink } from '../../../shared/utils/follow-link-config.model';
import { ValidateEmailNotTaken } from './validators/email-taken.validator';
+import { Registration } from '../../../core/shared/registration.model';
+import { EpersonRegistrationService } from '../../../core/data/eperson-registration.service';
@Component({
selector: 'ds-eperson-form',
@@ -121,7 +123,7 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
* Observable whether or not the admin is allowed to reset the EPerson's password
* TODO: Initialize the observable once the REST API supports this (currently hardcoded to return false)
*/
- canReset$: Observable = observableOf(false);
+ canReset$: Observable;
/**
* Observable whether or not the admin is allowed to delete the EPerson
@@ -167,17 +169,20 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
*/
emailValueChangeSubscribe: Subscription;
- constructor(protected changeDetectorRef: ChangeDetectorRef,
- public epersonService: EPersonDataService,
- public groupsDataService: GroupDataService,
- private formBuilderService: FormBuilderService,
- private translateService: TranslateService,
- private notificationsService: NotificationsService,
- private authService: AuthService,
- private authorizationService: AuthorizationDataService,
- private modalService: NgbModal,
- private paginationService: PaginationService,
- public requestService: RequestService) {
+ constructor(
+ protected changeDetectorRef: ChangeDetectorRef,
+ public epersonService: EPersonDataService,
+ public groupsDataService: GroupDataService,
+ private formBuilderService: FormBuilderService,
+ private translateService: TranslateService,
+ private notificationsService: NotificationsService,
+ private authService: AuthService,
+ private authorizationService: AuthorizationDataService,
+ private modalService: NgbModal,
+ private paginationService: PaginationService,
+ public requestService: RequestService,
+ private epersonRegistrationService: EpersonRegistrationService,
+ ) {
this.subs.push(this.epersonService.getActiveEPerson().subscribe((eperson: EPerson) => {
this.epersonInitial = eperson;
if (hasValue(eperson)) {
@@ -310,6 +315,7 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
this.canDelete$ = activeEPerson$.pipe(
switchMap((eperson) => this.authorizationService.isAuthorized(FeatureID.CanDelete, hasValue(eperson) ? eperson.self : undefined))
);
+ this.canReset$ = observableOf(true);
});
}
@@ -479,6 +485,26 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
this.isImpersonated = false;
}
+ /**
+ * Sends an email to current eperson address with the information
+ * to reset password
+ */
+ resetPassword() {
+ if (hasValue(this.epersonInitial.email)) {
+ this.epersonRegistrationService.registerEmail(this.epersonInitial.email).pipe(getFirstCompletedRemoteData())
+ .subscribe((response: RemoteData) => {
+ if (response.hasSucceeded) {
+ this.notificationsService.success(this.translateService.get('admin.access-control.epeople.actions.reset'),
+ this.translateService.get('forgot-email.form.success.content', {email: this.epersonInitial.email}));
+ } else {
+ this.notificationsService.error(this.translateService.get('forgot-email.form.error.head'),
+ this.translateService.get('forgot-email.form.error.content', {email: this.epersonInitial.email}));
+ }
+ }
+ );
+ }
+ }
+
/**
* Cancel the current edit when component is destroyed & unsub all subscriptions
*/