diff --git a/config/user.role.contributor.yml b/config/user.role.contributor.yml index e702fb568..5f260b723 100644 --- a/config/user.role.contributor.yml +++ b/config/user.role.contributor.yml @@ -10,6 +10,7 @@ dependencies: - node - reliefweb_files - reliefweb_form + - reliefweb_revisions id: contributor label: Contributor weight: 9 @@ -24,4 +25,5 @@ permissions: - 'edit own image_report media' - 'edit own report content' - 'update media' + - 'view entity history' - 'view own unpublished media' diff --git a/html/modules/custom/reliefweb_entities/src/Entity/Report.php b/html/modules/custom/reliefweb_entities/src/Entity/Report.php index d4dbc56be..8d22935fb 100644 --- a/html/modules/custom/reliefweb_entities/src/Entity/Report.php +++ b/html/modules/custom/reliefweb_entities/src/Entity/Report.php @@ -242,8 +242,15 @@ public function preSave(EntityStorageInterface $storage) { } } + // Update the entity status based on the user posting rights. + $this->updateModerationStatusFromPostingRights(); + // Change the status to `embargoed` if there is an embargo date. - if (!empty($this->field_embargo_date->value) && $this->getModerationStatus() !== 'draft') { + if (!empty($this->field_embargo_date->value) && in_array($this->getModerationStatus(), [ + 'embargoed', + 'to-review', + 'published', + ])) { $this->setModerationStatus('embargoed'); $message = strtr('Embargoed (to be automatically published on @date).', [ @@ -258,9 +265,6 @@ public function preSave(EntityStorageInterface $storage) { // Prepare notifications. $this->preparePublicationNotification(); - // Update the entity status based on the user posting rights. - $this->updateModerationStatusFromPostingRights(); - // Update the entity status based on the source(s) moderation status. $this->updateModerationStatusFromSourceStatus(); diff --git a/html/modules/custom/reliefweb_entities/src/Services/ReportFormAlter.php b/html/modules/custom/reliefweb_entities/src/Services/ReportFormAlter.php index d52c58e15..a9708690d 100644 --- a/html/modules/custom/reliefweb_entities/src/Services/ReportFormAlter.php +++ b/html/modules/custom/reliefweb_entities/src/Services/ReportFormAlter.php @@ -465,7 +465,6 @@ protected function alterFieldsForContributors(array &$form, FormStateInterface $ // Hide fields. $form['field_bury']['#access'] = FALSE; $form['field_feature']['#access'] = FALSE; - $form['field_notify']['#access'] = FALSE; $form['field_headline']['#access'] = FALSE; $form['field_headline_title']['#access'] = FALSE; diff --git a/html/modules/custom/reliefweb_fields/components/reliefweb-user-posting-rights/reliefweb-user-posting-rights.css b/html/modules/custom/reliefweb_fields/components/reliefweb-user-posting-rights/reliefweb-user-posting-rights.css index 254b8e659..45b4de6f8 100644 --- a/html/modules/custom/reliefweb_fields/components/reliefweb-user-posting-rights/reliefweb-user-posting-rights.css +++ b/html/modules/custom/reliefweb_fields/components/reliefweb-user-posting-rights/reliefweb-user-posting-rights.css @@ -28,12 +28,14 @@ margin: 0 8px; } .field--type-reliefweb-user-posting-rights label span, -.field--type-reliefweb-user-posting-rights label select { +.field--type-reliefweb-user-posting-rights label select, +.field--type-reliefweb-user-posting-rights label input[type="text"] { display: inline-block; margin: 0 8px 0 0; vertical-align: middle; } -.field--type-reliefweb-user-posting-rights label select { +.field--type-reliefweb-user-posting-rights label select, +.field--type-reliefweb-user-posting-rights [data-filters] label input[type="text"] { width: auto; } .field--type-reliefweb-user-posting-rights div[data-filters] ~ ul li { @@ -41,9 +43,18 @@ flex-wrap: wrap; align-items: center; } + .field--type-reliefweb-user-posting-rights div[data-filters][data-job="all"][data-training="all"][data-report="all"] ~ ul li { display: flex; } + +.field--type-reliefweb-user-posting-rights div[data-filters]:not([data-name=""]) ~ ul li { + display: none !important; +} +.field--type-reliefweb-user-posting-rights div[data-filters]:not([data-name=""]) ~ ul li[data-user-filtered] { + display: flex !important; +} + .field--type-reliefweb-user-posting-rights div[data-filters][data-job="0"] ~ ul li[data-job="0"] { display: flex; } diff --git a/html/modules/custom/reliefweb_fields/components/reliefweb-user-posting-rights/reliefweb-user-posting-rights.js b/html/modules/custom/reliefweb_fields/components/reliefweb-user-posting-rights/reliefweb-user-posting-rights.js index 2ee8e1cf7..d2510a703 100644 --- a/html/modules/custom/reliefweb_fields/components/reliefweb-user-posting-rights/reliefweb-user-posting-rights.js +++ b/html/modules/custom/reliefweb_fields/components/reliefweb-user-posting-rights/reliefweb-user-posting-rights.js @@ -84,6 +84,27 @@ return label; }, + /** + * Create a filter for users. + */ + createUserFilter: function () { + let name = 'name'; + + var select = document.createElement('input'); + select.setAttribute('type', 'text'); + select.setAttribute('data-name', name); + + var span = document.createElement('span'); + span.appendChild(document.createTextNode(t('user id, name, email'))); + + var label = document.createElement('label'); + label.appendChild(span); + label.appendChild(select); + label.className = name; + + return label; + }, + /** * Create the user notes field. */ @@ -118,6 +139,7 @@ container.setAttribute('data-job', data.job); container.setAttribute('data-training', data.training); container.setAttribute('data-report', data.report); + container.setAttribute('data-name', [data.id, data.name, data.mail].join(', ')); // User info. var info = document.createElement('div'); @@ -208,6 +230,7 @@ container.setAttribute('data-job', 'all'); container.setAttribute('data-training', 'all'); container.setAttribute('data-report', 'all'); + container.setAttribute('data-name', ''); var title = document.createElement('span'); title.appendChild(document.createTextNode(t('Filter: '))); @@ -218,6 +241,9 @@ container.appendChild(this.createSelect('training', '', false, true)); container.appendChild(this.createSelect('report', '', false, true)); + // User filter. + container.appendChild(this.createUserFilter()); + return container; }, @@ -259,6 +285,7 @@ // Handle change events on the different select elements in the form. container.addEventListener('change', this.handleChange.bind(this)); + container.addEventListener('keyup', this.handleChange.bind(this)); // Handle focus out events from notes fields. container.addEventListener('focusout', this.handleFocusOut.bind(this)); @@ -525,6 +552,29 @@ parent = this.getParentElement(target, 'LI'); } + // Set the attribute to the value of the select element. + parent.setAttribute('data-' + name, target.value); + parent.setAttribute('data-modified', ''); + this.updateData(); + } + } + else if (target && target.tagName === 'INPUT') { + var name = target.getAttribute('data-name'); + var parent = target.parentNode.parentNode; + + // Filter on user name. + if (parent.hasAttribute('data-filters') && name === 'name') { + let grandParent = parent.parentNode; + if (grandParent.querySelectorAll('li[data-user-filtered]').length > 0) { + Array.from(grandParent.querySelectorAll('li[data-user-filtered]')) + .forEach(e => e.removeAttribute('data-user-filtered')); + } + + if (target.value !== '') { + Array.from(grandParent.querySelectorAll('li[data-name*="' + target.value + '"]')) + .forEach(e => e.setAttribute('data-user-filtered', '')); + } + // Set the attribute to the value of the select element. parent.setAttribute('data-' + name, target.value); parent.setAttribute('data-modified', ''); diff --git a/html/themes/custom/common_design_subtheme/templates/form/node-edit-form--report.html.twig b/html/themes/custom/common_design_subtheme/templates/form/node-edit-form--report.html.twig index 5d96b44f5..677e8c843 100644 --- a/html/themes/custom/common_design_subtheme/templates/form/node-edit-form--report.html.twig +++ b/html/themes/custom/common_design_subtheme/templates/form/node-edit-form--report.html.twig @@ -45,6 +45,7 @@ }%} {% set submission_sections = { + 'editorial-flags': 'Notify'|t, 'actions': 'Save'|t, 'edit-revision-information': 'Revisions'|t, }%} @@ -128,6 +129,11 @@ {{ form.field_feature }} {{ form.field_notify }} +{% else %} +
{% endif %}