Skip to content

Commit 59e5f71

Browse files
117287: Fixed group form not working correctly anymore when switching between different groups
Also fixed edit ePerson not showing the group names
1 parent f03ed89 commit 59e5f71

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

src/app/access-control/epeople-registry/eperson-form/eperson-form.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ <h5>{{messagePrefix + '.groupsEPersonIsMemberOf' | translate}}</h5>
7171
{{ dsoNameService.getName(group) }}
7272
</a>
7373
</td>
74-
<td class="align-middle">{{ dsoNameService.getName(undefined) }}</td>
74+
<td class="align-middle">
75+
{{ dsoNameService.getName((group.object | async)?.payload) }}
76+
</td>
7577
</tr>
7678
</tbody>
7779
</table>

src/app/access-control/group-registry/group-form/group-form.component.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
Observable,
1414
Subscription, combineLatest,
1515
} from 'rxjs';
16-
import { map, switchMap, take, debounceTime, startWith, filter } from 'rxjs/operators';
16+
import { map, switchMap, take, debounceTime } from 'rxjs/operators';
1717
import { getCollectionEditRolesRoute } from '../../../collection-page/collection-page-routing-paths';
1818
import { getCommunityEditRolesRoute } from '../../../community-page/community-page-routing-paths';
1919
import { DSpaceObjectDataService } from '../../../core/data/dspace-object-data.service';
@@ -35,7 +35,7 @@ import {
3535
} from '../../../core/shared/operators';
3636
import { AlertType } from '../../../shared/alert/aletr-type';
3737
import { ConfirmationModalComponent } from '../../../shared/confirmation-modal/confirmation-modal.component';
38-
import { hasValue, isNotEmpty, hasValueOperator, hasNoValue } from '../../../shared/empty.util';
38+
import { hasValue, isNotEmpty, hasValueOperator } from '../../../shared/empty.util';
3939
import { FormBuilderService } from '../../../shared/form/builder/form-builder.service';
4040
import { NotificationsService } from '../../../shared/notifications/notifications.service';
4141
import { followLink } from '../../../shared/utils/follow-link-config.model';
@@ -164,11 +164,16 @@ export class GroupFormComponent implements OnInit, OnDestroy {
164164
this.activeGroupLinkedDSO$ = this.getActiveGroupLinkedDSO();
165165
this.linkedEditRolesRoute$ = this.getLinkedEditRolesRoute();
166166
this.canEdit$ = this.activeGroupLinkedDSO$.pipe(
167-
filter((dso: DSpaceObject) => hasNoValue(dso)),
168-
switchMap(() => this.activeGroup$),
169-
hasValueOperator(),
170-
switchMap((group: Group) => this.authorizationService.isAuthorized(FeatureID.CanDelete, group.self)),
171-
startWith(false),
167+
switchMap((dso: DSpaceObject) => {
168+
if (hasValue(dso)) {
169+
return [false];
170+
} else {
171+
return this.activeGroup$.pipe(
172+
hasValueOperator(),
173+
switchMap((group: Group) => this.authorizationService.isAuthorized(FeatureID.CanDelete, group.self)),
174+
);
175+
}
176+
}),
172177
);
173178
this.initialisePage();
174179
}
@@ -216,33 +221,39 @@ export class GroupFormComponent implements OnInit, OnDestroy {
216221
combineLatest([
217222
this.activeGroup$,
218223
this.canEdit$,
219-
this.activeGroupLinkedDSO$.pipe(take(1)),
224+
this.activeGroupLinkedDSO$,
220225
]).subscribe(([activeGroup, canEdit, linkedObject]) => {
221226

222227
if (activeGroup != null) {
223228

224229
// Disable group name exists validator
225230
this.formGroup.controls.groupName.clearAsyncValidators();
226231

227-
if (linkedObject?.name) {
228-
this.formBuilderService.insertFormGroupControl(1, this.formGroup, this.formModel, groupCommunityModel);
229-
this.groupDescription = this.formGroup.get('groupCommunity');
232+
if (isNotEmpty(linkedObject?.name)) {
233+
if (!this.formGroup.controls.groupCommunity) {
234+
this.formBuilderService.insertFormGroupControl(1, this.formGroup, this.formModel, groupCommunityModel);
235+
this.groupDescription = this.formGroup.get('groupCommunity');
236+
}
230237
this.formGroup.patchValue({
231238
groupName: activeGroup.name,
232239
groupCommunity: linkedObject?.name ?? '',
233240
groupDescription: activeGroup.firstMetadataValue('dc.description'),
234241
});
235242
} else {
243+
this.formModel = [
244+
groupNameModel,
245+
groupDescriptionModel,
246+
];
236247
this.formGroup.patchValue({
237248
groupName: activeGroup.name,
238249
groupDescription: activeGroup.firstMetadataValue('dc.description'),
239250
});
240251
}
241-
setTimeout(() => {
242-
if (!canEdit || activeGroup.permanent) {
243-
this.formGroup.disable();
244-
}
245-
}, 200);
252+
if (!canEdit || activeGroup.permanent) {
253+
this.formGroup.disable();
254+
} else {
255+
this.formGroup.enable();
256+
}
246257
}
247258
})
248259
);
@@ -471,14 +482,15 @@ export class GroupFormComponent implements OnInit, OnDestroy {
471482
*/
472483
getLinkedEditRolesRoute(): Observable<string> {
473484
return this.activeGroupLinkedDSO$.pipe(
485+
hasValueOperator(),
474486
map((dso: DSpaceObject) => {
475487
switch ((dso as any).type) {
476488
case Community.type.value:
477489
return getCommunityEditRolesRoute(dso.id);
478490
case Collection.type.value:
479491
return getCollectionEditRolesRoute(dso.id);
480492
}
481-
})
493+
}),
482494
);
483495
}
484496
}

0 commit comments

Comments
 (0)