Skip to content
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

RW 1058: User posting rights for reports #908

Merged
merged 102 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
d682586
feat: Add report to user posting rights
attiks Sep 19, 2024
bb17ae4
feat: Add report to user posting rights
attiks Sep 19, 2024
ea48846
feat: Add report to user posting rights on people
attiks Sep 19, 2024
f3e73c0
feat: Allow anon to create reports
attiks Sep 19, 2024
8d02df9
feat: Limit sources
attiks Sep 19, 2024
c1bc848
feat: My posts
attiks Sep 19, 2024
c06c1a1
feat: Moderate reports
attiks Sep 19, 2024
b2b1a68
feat: Report submission
attiks Sep 19, 2024
5b4f5e4
Merge branch 'develop' into RW-1058
attiks Sep 20, 2024
0f1866d
feat: Source revision log
attiks Sep 20, 2024
a975f0e
feat: Form actions for report
attiks Sep 20, 2024
329569f
feat: Source revision log
attiks Sep 20, 2024
15b7028
Merge branch 'RW-1058' of github.com:UN-OCHA/rwint9-site into RW-1058
attiks Sep 20, 2024
7cd882f
Merge branch 'develop' into RW-1058
orakili Sep 24, 2024
3421cf0
Merge branch 'develop' into RW-1058
orakili Sep 26, 2024
feee802
feat: Add contributor role
attiks Sep 26, 2024
e1e0089
chore: Small fixes
attiks Sep 26, 2024
4675322
chore: Add pending state
attiks Sep 26, 2024
f9ba508
chore: no more pending
attiks Sep 26, 2024
0d7e02e
test: Basic report test
attiks Sep 30, 2024
787ab88
test: Basic report test
attiks Sep 30, 2024
e4ef535
test: Create terms if needed
attiks Sep 30, 2024
2c0c602
test: Create terms if needed
attiks Sep 30, 2024
34a141b
test: Basic report test
attiks Sep 30, 2024
b48a5eb
test: Basic report test for contributor
attiks Sep 30, 2024
929290d
test: Basic report test for contributor
attiks Sep 30, 2024
3de412c
test: Basic report test for contributor
attiks Sep 30, 2024
ec035e0
test: Basic report test for contributor
attiks Sep 30, 2024
52e8d61
test: Basic report test for contributor
attiks Oct 1, 2024
1caaa34
Merge pull request #905 from UN-OCHA/RW-1058-tests
attiks Oct 1, 2024
67c230f
Merge branch 'develop' into RW-1058
attiks Oct 1, 2024
5afe818
chore: Rename role
attiks Oct 1, 2024
d3f2e79
Update html/modules/custom/reliefweb_moderation/src/Services/ReportMo…
attiks Oct 1, 2024
b066d00
chore: Limit filter options depending on permission
attiks Oct 1, 2024
07b1bad
chore: Add refused, add own version of updateModerationStatusFromPost…
attiks Oct 1, 2024
ad431bf
chore: Add refused, add own version of updateModerationStatusFromPost…
attiks Oct 1, 2024
43f1bba
chore: Add refused, add own version of updateModerationStatusFromPost…
attiks Oct 1, 2024
8479003
chore: Fix static
attiks Oct 1, 2024
fab897d
feat: Allow contributor to upload media
attiks Oct 1, 2024
d03c8b3
feat: Allow contributor to edit own
attiks Oct 1, 2024
a6b8a71
bug: namespace
attiks Oct 1, 2024
ebc48f6
feat: Allow contributor to edit own
attiks Oct 1, 2024
a194cd9
Merge pull request #909 from UN-OCHA/feature/RW-1058-tests
orakili Oct 2, 2024
f7bb92b
Merge branch 'develop' into feature/RW-1058
orakili Oct 2, 2024
893ca82
chore: Move updateModerationStatusFromSourceStatus to DocumentTrait.php
attiks Oct 2, 2024
28406d5
chore: Move updateModerationStatusFromSourceStatus to DocumentTrait.php
attiks Oct 2, 2024
f3bfdf9
test: Report for blocked source
attiks Oct 2, 2024
db6a089
test: Fix path in entraid tests
attiks Oct 2, 2024
d9d854b
chore: Specify test URL
attiks Oct 2, 2024
7d16e25
Merge branch 'develop' into feature/RW-1058
orakili Oct 3, 2024
1ee0d0e
feat: Allow user manager to assign contgributor role
attiks Oct 7, 2024
66e93e3
Merge branch 'develop' into feature/RW-1058
cafuego Oct 9, 2024
ed07502
feat: Display right indicators
attiks Oct 14, 2024
a88a08f
feat: access private files
attiks Oct 15, 2024
d597d81
feat: grant access to display source attention messages
attiks Oct 15, 2024
cbdcdc9
bug: trim on null
attiks Oct 15, 2024
e7cb395
Merge remote-tracking branch 'origin/develop' into feature/RW-1058
attiks Oct 15, 2024
6ccae20
feat: Add to-review to filters
attiks Oct 15, 2024
2824323
feat: Link on dashboard
attiks Oct 15, 2024
bfef48b
feat: Add save as draft for published
attiks Oct 16, 2024
b7fec0f
Merge remote-tracking branch 'origin/develop' into feature/RW-1058
attiks Oct 16, 2024
278076f
test: Add tests for multiple sources
attiks Oct 16, 2024
edc031d
feat: Logic for status
attiks Oct 17, 2024
e50ff9f
feat: Block saving if user right is blocked
attiks Oct 17, 2024
c7e4fd5
feat: Block saving if user right is blocked
attiks Oct 17, 2024
f03900c
test: Block saving if user right is blocked
attiks Oct 17, 2024
71c94cc
Merge branch 'develop' into feature/RW-1058
attiks Oct 18, 2024
c0badb0
chore: Fix wording on dashboard
attiks Nov 14, 2024
9bf79cc
feat: Add embergoed filter
attiks Nov 14, 2024
4c11c81
feat: Unverified for single source, to-review
attiks Nov 14, 2024
82f5a19
Merge branch 'develop' into feature/RW-1058
attiks Nov 14, 2024
82f8890
feat: Add reference filter
attiks Nov 14, 2024
89d9736
Merge branch 'feature/RW-1058' of github.com:UN-OCHA/rwint9-site into…
attiks Nov 14, 2024
25f1dc1
bug: twig v3.14.1 is broken
attiks Nov 15, 2024
69f0d96
test: new logic for to-review
attiks Nov 15, 2024
ef60462
Merge branch 'develop' into feature/RW-1058
attiks Nov 15, 2024
17e3d3c
feat: Hide fields for contributors
attiks Nov 15, 2024
3ea5916
test: No origin field needed
attiks Nov 15, 2024
d40d016
test: No origin field needed for contributor
attiks Nov 15, 2024
eeb4fc7
Merge branch 'develop' into feature/RW-1058
attiks Nov 18, 2024
f85e704
Update html/modules/custom/reliefweb_entities/src/Services/ReportForm…
attiks Nov 20, 2024
6ab6a7a
Update html/themes/custom/common_design_subtheme/components/rw-people…
attiks Nov 20, 2024
c5c315c
Update html/themes/custom/common_design_subtheme/templates/form/node-…
attiks Nov 20, 2024
174535e
Merge branch 'develop' into feature/RW-1058
attiks Nov 20, 2024
53e81c6
Update html/themes/custom/common_design_subtheme/templates/form/node-…
attiks Nov 21, 2024
5e5fca9
feat: Add a if for reports and use N/A or something like that as valu…
attiks Nov 21, 2024
77ff6f5
feat: I do not think this is useful for reports and is not currently …
attiks Nov 21, 2024
250b40f
feat: Body format "markdown" should not be allowed for contributor
attiks Nov 21, 2024
3f03cd3
feat: Source guidelines should only be shown to editors
attiks Nov 21, 2024
3d25a24
feat: Statuses irrelevant to job/training displayed on My Posts page …
attiks Nov 21, 2024
766ff2e
feat: Reports posted by editors appear as "Unverified" → probably sho…
attiks Nov 21, 2024
01b0308
Merge remote-tracking branch 'origin/develop' into feature/RW-1058
attiks Nov 26, 2024
1626c30
feat: URL optional for contributors
attiks Nov 26, 2024
c3a9bf8
feat: Contributir can use on-hold
attiks Nov 26, 2024
6b5ce4f
feat: Posting rights
attiks Nov 28, 2024
8d4f6b8
Merge branch 'develop' into feature/RW-1058
attiks Nov 28, 2024
d1b69dd
chore: docksal
attiks Nov 28, 2024
e39884d
Merge branch 'feature/RW-1058' of github.com:UN-OCHA/rwint9-site into…
attiks Nov 28, 2024
85cc1b3
fix: status when unverified and allowed and add messages with the dif…
orakili Dec 4, 2024
685a961
fix: hide origin field but perserve validation of origin notes
orakili Dec 4, 2024
78f1f76
Merge pull request #958 from UN-OCHA/feature/RW-1058-fixes-1
attiks Dec 4, 2024
2cc3119
Merge branch 'develop' into feature/RW-1058
orakili Dec 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .docksal/docksal-local.env
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
MYSQL_PORT_MAPPING='3380:3306'
XDEBUG_ENABLED=1
XDEBUG_MODE=coverage
2 changes: 1 addition & 1 deletion .docksal/docksal.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DOCKSAL_STACK=default
DOCROOT=html
DB_IMAGE="docksal/mariadb:10.6"
CLI_IMAGE='docksal/cli:php8.2-build'
CLI_IMAGE='docksal/cli:php8.3-build'
2 changes: 2 additions & 0 deletions .docksal/etc/mysql/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mysqld]
innodb_force_recovery=0
3 changes: 1 addition & 2 deletions .docksal/etc/php/php.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
; Mail settings
sendmail_path = '/usr/bin/msmtp -t --host=mail --port=1025 --read-envelope-from'
xdebug.mode=coverage
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
docker compose -f tests/docker-compose.yml exec -T drupal chmod -R 777 /srv/www/html/sites/default/files /srv/www/html/sites/default/private
docker compose -f tests/docker-compose.yml exec -T drupal mkdir -p /srv/www/html/build/logs
docker compose -f tests/docker-compose.yml exec -T drupal chmod -R 777 /srv/www/html/build/logs
docker compose -f tests/docker-compose.yml exec -T -w /srv/www -e XDEBUG_MODE=coverage -e BROWSERTEST_OUTPUT_DIRECTORY=/srv/www/html/sites/default/files/browser_output -e DTT_BASE_URL=http://127.0.0.1 drupal ./vendor/bin/phpunit --coverage-clover /srv/www/html/build/logs/clover.xml --debug
docker compose -f tests/docker-compose.yml exec -T -w /srv/www -e XDEBUG_MODE=coverage -e BROWSERTEST_OUTPUT_DIRECTORY=/srv/www/html/sites/default/files/browser_output -e SIMPLETEST_BASE_URL=http://127.0.0.1 -e DTT_BASE_URL=http://127.0.0.1 drupal ./vendor/bin/phpunit --coverage-clover /srv/www/html/build/logs/clover.xml --debug
docker cp "$(docker compose -f tests/docker-compose.yml ps -q drupal)":/srv/www/html/build/logs/clover.xml .
env:
fail-fast: true
Expand Down
2 changes: 1 addition & 1 deletion config/filter.format.markdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ filters:
status: false
weight: 0
settings:
replace_empty: '0'
replace_empty: 0
14 changes: 14 additions & 0 deletions config/system.action.user_add_role_action.contributor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
uuid: 8a1c6d2a-cf03-48d7-9dc8-ba12b7239159
langcode: en
status: true
dependencies:
config:
- user.role.contributor
module:
- user
id: user_add_role_action.contributor
label: 'Add the Contributor role role to the selected user(s)'
type: user
plugin: user_add_role_action
configuration:
rid: contributor
14 changes: 14 additions & 0 deletions config/system.action.user_remove_role_action.contributor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
uuid: e0c6f28b-74a1-41a4-a75f-b9c12fe98676
langcode: en
status: true
dependencies:
config:
- user.role.contributor
module:
- user
id: user_remove_role_action.contributor
label: 'Remove the Contributor role role from the selected user(s)'
type: user
plugin: user_remove_role_action
configuration:
rid: contributor
2 changes: 0 additions & 2 deletions config/user.role.authenticated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ langcode: en
status: true
dependencies:
config:
- filter.format.markdown
- filter.format.markdown_editor
- filter.format.token_markdown
- node.type.job
Expand Down Expand Up @@ -49,7 +48,6 @@ permissions:
- 'subscribe to jobs'
- 'subscribe to training'
- 'use enhanced input forms'
- 'use text format markdown'
- 'use text format markdown_editor'
- 'use text format token_markdown'
- 'view media'
Expand Down
27 changes: 27 additions & 0 deletions config/user.role.contributor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
uuid: 42dacb5f-f71a-4e37-858e-d4cf46729e39
langcode: en
status: true
dependencies:
config:
- media.type.image_report
- node.type.report
module:
- media
- node
- reliefweb_files
- reliefweb_form
id: contributor
label: Contributor
weight: 9
is_admin: null
permissions:
- 'access reliefweb private files'
- 'create image_report media'
- 'create report content'
- 'delete media'
- 'delete own image_report media'
- 'display source attention messages'
- 'edit own image_report media'
- 'edit own report content'
- 'update media'
- 'view own unpublished media'
1 change: 1 addition & 0 deletions config/user.role.user_manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ permissions:
- 'administer subscriptions'
- 'administer users'
- 'assign beta_tester role'
- 'assign contributor role'
- 'assign editor role'
- 'assign external_disaster_manager role'
- 'assign job_importer role'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function reliefweb_entities_entity_bundle_field_info_alter(array &$fields, Entit
* Add bundle classes to nodes and terms to handle business logic.
*/
function reliefweb_entities_entity_bundle_info_alter(&$bundles) {
$namespace = '\Drupal\reliefweb_entities\Entity';
$namespace = 'Drupal\reliefweb_entities\Entity';

foreach ($bundles as $entity_type_id => $items) {
foreach ($items as $bundle => $info) {
Expand All @@ -96,6 +96,8 @@ function reliefweb_entities_entity_bundle_info_alter(&$bundles) {
}
if ($class !== FALSE && is_subclass_of($class, BundleEntityInterface::class)) {
$label = ucwords(str_replace(['_', '-'], ' ', $bundle));
// No leading \ otherwise EntityTypeRepository::getEntityTypeFromClass
// fails.
$bundles[$entity_type_id][$bundle]['class'] = $class;
$bundles[$entity_type_id][$bundle]['label'] = $label;
}
Expand Down
39 changes: 39 additions & 0 deletions html/modules/custom/reliefweb_entities/src/DocumentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Entity\RevisionLogInterface;
use Drupal\Core\Field\EntityReferenceFieldItemList;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
Expand Down Expand Up @@ -394,4 +395,42 @@ protected function updateSourceModerationStatus() {
}
}

/**
* Update the status to refused if any of the sources is blocked.
*/
protected function updateModerationStatusFromSourceStatus() {
if (!$this->hasField('field_source') || $this->field_source->isEmpty()) {
return;
}

$blocked = [];
foreach ($this->field_source as $item) {
$source = $item->entity;
if (empty($source) || !($source instanceof Source)) {
continue;
}

if ($source->getModerationStatus() === 'blocked') {
$blocked[] = $source->label();
}
}

if (!empty($blocked)) {
$this->setModerationStatus('refused');

// Add a message to the revision log.
if ($this instanceof RevisionLogInterface) {
$message = 'Submissions from "' . implode('", "', $blocked) . '" are no longer allowed.';

$log = $this->getRevisionLogMessage();
if (empty($log)) {
$this->setRevisionLogMessage($message);
}
else {
$this->setRevisionLogMessage($message . ' ' . $log);
}
}
}
}

}
111 changes: 108 additions & 3 deletions html/modules/custom/reliefweb_entities/src/Entity/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
use Drupal\reliefweb_entities\DocumentTrait;
use Drupal\reliefweb_moderation\EntityModeratedInterface;
use Drupal\reliefweb_moderation\EntityModeratedTrait;
use Drupal\reliefweb_moderation\Helpers\UserPostingRightsHelper;
use Drupal\reliefweb_revisions\EntityRevisionedInterface;
use Drupal\reliefweb_revisions\EntityRevisionedTrait;
use Drupal\reliefweb_utility\Helpers\DateHelper;
use Drupal\reliefweb_utility\Helpers\ReliefWebStateHelper;
use Drupal\reliefweb_utility\Helpers\TaxonomyHelper;
use Drupal\reliefweb_utility\Helpers\UrlHelper;
use Drupal\reliefweb_utility\Helpers\UserHelper;

/**
* Bundle class for report nodes.
Expand Down Expand Up @@ -210,8 +213,6 @@ public function getAttachments(?array $build = NULL) {
* {@inheritdoc}
*/
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);

// Change the publication date if bury is selected, to the original
// publication date.
if (!empty($this->field_bury->value) && !$this->field_original_publication_date->isEmpty()) {
Expand Down Expand Up @@ -249,13 +250,21 @@ public function preSave(EntityStorageInterface $storage) {
'@date' => DateHelper::format($this->field_embargo_date->value, 'custom', 'd M Y H:i e'),
]);

$log = trim($this->getRevisionLogMessage());
$log = !empty($this->getRevisionLogMessage()) ? trim($this->getRevisionLogMessage()) : '';
$log = $message . (!empty($log) ? "\n" . $log : '');
$this->setRevisionLogMessage($log);
}

// 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();

parent::preSave($storage);
}

/**
Expand Down Expand Up @@ -353,6 +362,102 @@ protected function sendPublicationNotification() {
->mail('reliefweb_entities', 'report_publication_notification', $to, $langcode, $parameters, $from, TRUE);
}

/**
* Update the status for the entity based on the user posting rights.
*/
protected function updateModerationStatusFromPostingRights() {
// In theory the revision user here, is the current user saving the entity.
/** @var \Drupal\user\UserInterface|null $user */
$user = $this->getRevisionUser();
$status = $this->getModerationStatus();

// Skip if there is no revision user. That should normally not happen with
// new content but some old revisions may reference users that don't exist
// anymore (which should not happen either but...).
if (empty($user)) {
return;
}

// For non editors, we determine the real status based on the user
// posting rights for the selected sources.
if (!UserHelper::userHasRoles(['editor'], $user) && in_array($status, ['to-review'])) {
// Retrieve the list of sources and check the user rights.
if (!$this->field_source->isEmpty()) {
// Extract source ids.
$sources = [];
foreach ($this->field_source as $item) {
if (!empty($item->target_id)) {
$sources[] = $item->target_id;
}
}

// Get the user's posting right for the document.
$rights = [];
foreach (UserPostingRightsHelper::getUserPostingRights($user, $sources) as $tid => $data) {
$rights[$data[$this->bundle()] ?? 0][] = $tid;
}

// Blocked for some sources.
if (!empty($rights[1])) {
$status = 'refused';
}
// Trusted for all the sources.
elseif (isset($rights[3]) && count($rights[3]) === count($sources)) {
$status = 'published';
}
// Trusted for at least 1.
elseif (isset($rights[3]) && count($rights[3]) > 0) {
$status = 'to-review';
}
// Allowed for all the sources.
elseif (isset($rights[2]) && count($rights[2]) === count($sources)) {
$status = 'to-review';
}
// Unverified for some sources.
else {
$status = 'pending';
}

$this->setModerationStatus($status);

// Add messages indicating the posting rights for easier review.
$message = '';
if (!empty($rights[1])) {
$message = trim($message . strtr(' Blocked user for @sources.', [
'@sources' => implode(', ', TaxonomyHelper::getSourceShortnames($rights[1])),
]));
}
if (!empty($rights[0])) {
$message = trim($message . strtr(' Unverified user for @sources.', [
'@sources' => implode(', ', TaxonomyHelper::getSourceShortnames($rights[0])),
]));
}
if (!empty($rights[2])) {
$message = trim($message . strtr(' Allowed user for @sources.', [
'@sources' => implode(', ', TaxonomyHelper::getSourceShortnames($rights[2])),
]));
}
if (!empty($rights[3])) {
$message = trim($message . strtr(' Trusted user for @sources.', [
'@sources' => implode(', ', TaxonomyHelper::getSourceShortnames($rights[3])),
]));
}

// Update the log message.
if (!empty($message)) {
$revision_log_field = $this->getEntityType()
->getRevisionMetadataKey('revision_log_message');

if (!empty($revision_log_field)) {
$log = trim($this->{$revision_log_field}->value ?? '');
$log = $message . (!empty($log) ? ' ' . $log : '');
$this->{$revision_log_field}->value = $log;
}
}
}
}
}

/**
* Temporarily store the email address to notify after publication.
*
Expand Down
26 changes: 14 additions & 12 deletions html/modules/custom/reliefweb_entities/src/Entity/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,20 @@ protected function getOrganizationDetails() {
$meta = [];

// Organization type.
$type = $this->field_organization_type->entity->label();
$meta['type'] = [
'type' => 'link',
'label' => $this->t('Organization type'),
'value' => [
'url' => RiverServiceBase::getRiverUrl('source', [
'search' => 'type.exact:"' . $type . '"',
]),
'title' => $type,
'external' => FALSE,
],
];
if ($this->hasField('field_organization_type') && !$this->get('field_organization_type')->isEmpty()) {
$type = $this->field_organization_type->entity->label();
$meta['type'] = [
'type' => 'link',
'label' => $this->t('Organization type'),
'value' => [
'url' => RiverServiceBase::getRiverUrl('source', [
'search' => 'type.exact:"' . $type . '"',
]),
'title' => $type,
'external' => FALSE,
],
];
}

// Headquarters.
$countries = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ public static function retrievePotentialNewSourceInformation(EntityModeratedInte
}

/**
* Add the user information to a job/training node form.
* Add the user information to a job/training/report node form.
*
* @param array $form
* The entity form.
Expand All @@ -594,7 +594,7 @@ protected function addUserInformation(array &$form, FormStateInterface $form_sta
$entity_id = $entity->id();
$bundle = $entity->bundle();

// It's only for jobs and training.
// It's only for jobs and trainings.
if (!in_array($bundle, ['job', 'training'])) {
return;
}
Expand Down
Loading
Loading