@@ -3,14 +3,20 @@ import Store from '@ember-data/store';
33import { inject as service } from '@ember/service' ;
44import { tagName } from '@ember-decorators/component' ;
55import Component from '@ember/component' ;
6+ import { computed } from '@ember/object' ;
67import { waitFor } from '@ember/test-waiters' ;
7- import { restartableTask } from 'ember-concurrency' ;
8+ import { tracked } from '@glimmer/tracking' ;
9+ import { restartableTask , task } from 'ember-concurrency' ;
10+ import { taskFor } from 'ember-concurrency-ts' ;
11+ import Intl from 'ember-intl/services/intl' ;
812import Toast from 'ember-toastr/services/toast' ;
913
1014import { layout } from 'ember-osf-web/decorators/component' ;
15+ import ModeratorModel from 'ember-osf-web/models/moderator' ;
1116import Registration from 'ember-osf-web/models/registration' ;
1217import SchemaResponseModel from 'ember-osf-web/models/schema-response' ;
1318import { getSchemaBlockGroups , SchemaBlock , SchemaBlockGroup } from 'ember-osf-web/packages/registration-schema' ;
19+ import CurrentUserService from 'ember-osf-web/services/current-user' ;
1420import captureException , { getApiErrorMessage } from 'ember-osf-web/utils/capture-exception' ;
1521
1622import template from './template' ;
@@ -20,20 +26,27 @@ import template from './template';
2026export default class RegistrationFormViewSchemaBlocks extends Component {
2127 @service store ! : Store ;
2228 @service toast ! : Toast ;
29+ @service currentUser ! : CurrentUserService ;
30+ @service intl ! : Intl ;
2331 // Required parameter
2432 registration ! : Registration ;
2533 revision ! : SchemaResponseModel ;
2634
2735 // Optional parameters
2836 updatedResponseIds ?: string [ ] ;
37+ mode ?: string ;
2938
3039 // Private properties
3140 schemaBlocks ?: SchemaBlock [ ] ;
3241 schemaBlockGroups ?: SchemaBlockGroup [ ] ;
3342 responses ?: { [ key : string ] : string } ;
3443
44+ @tracked currentModerator ?: ModeratorModel ;
45+
46+ @computed ( 'currentModerator' , 'registration.{latestResponse.content,schemaResponses.length}' )
3547 get showMetadata ( ) {
36- return this . registration . latestResponse . content && ! this . registration . latestResponse . get ( 'isOriginalResponse' ) ;
48+ return this . registration . latestResponse . content && ! this . registration . latestResponse . get ( 'isOriginalResponse' )
49+ || ( Boolean ( this . currentModerator ) && this . registration . schemaResponses . length > 1 ) ;
3750 }
3851
3952 @restartableTask ( { on : 'didReceiveAttrs' } )
@@ -55,7 +68,26 @@ export default class RegistrationFormViewSchemaBlocks extends Component {
5568 }
5669 }
5770
71+ @task
72+ @waitFor
73+ async loadCurrentModerator ( ) {
74+ try {
75+ this . currentModerator = await this . store . findRecord ( 'moderator' , this . currentUser . currentUserId ! ,
76+ {
77+ adapterOptions : {
78+ providerId : this . registration . provider . get ( 'id' ) ,
79+ } ,
80+ } ) ;
81+ } catch ( e ) {
82+ captureException ( e ) ;
83+ this . toast . error ( this . intl . t ( 'registries.overviewHeader.needModeratorPermission' ) ) ;
84+ }
85+ }
86+
5887 didReceiveAttrs ( ) {
59- assert ( 'OverviewFormRenderer needs a registration' , Boolean ( this . registration ) ) ;
88+ assert ( 'OverviewFormRenderer needs a registration' , Boolean ( this . registration ) ) ;
89+ if ( this . mode === 'moderator' ) {
90+ taskFor ( this . loadCurrentModerator ) . perform ( ) ;
91+ }
6092 }
6193}
0 commit comments