Skip to content

Commit

Permalink
Report User
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfyWin committed Oct 21, 2024
1 parent 62ee780 commit 2ef5377
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 3 deletions.
47 changes: 47 additions & 0 deletions src/main/community/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,53 @@ public function disableAction(Request $request): JsonResponse
}, $processed));
}

/**
* @Route("/list/reported", name="list_reported", methods={"GET"})
*/
public function listReportedAction(Request $request): JsonResponse
{
$this->checkPermission('IS_AUTHENTICATED_FULLY', null, [], true);

return new JsonResponse($this->crud->list(
User::class,
array_merge($request->query->all(), ['hiddenFilters' => array_merge($this->getDefaultHiddenFilters(), [
'reported' => true,
])]),
$this->getOptions()['list']
));
}

/**
* @ApiDoc(
* description="Report a list of users.",
* queryString={
* {"name": "ids[]", "type": {"string", "integer"}, "description": "The object id or uuid."}
* }
* )
*
* @Route("/report", name="report", methods={"PUT"})
*/
public function reportAction(Request $request): JsonResponse
{
/** @var User[] $users */
$users = $this->decodeIdsString($request, User::class);

$this->om->startFlushSuite();

$processed = [];
foreach ($users as $user) {
if ($this->checkPermission('ADMINISTRATE', $user)) {
$this->manager->report($user);
$processed[] = $user;
}
}
$this->om->endFlushSuite();

return new JsonResponse(array_map(function (User $user) {
return $this->serializer->serialize($user);
}, $processed));
}

/**
* @Route("/disable_inactive", name="disable_inactive", methods={"PUT"})
*/
Expand Down
50 changes: 50 additions & 0 deletions src/main/community/Resources/modules/actions/user/report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {createElement} from 'react'
import get from 'lodash/get'

import {url} from '#/main/app/api'
import {ASYNC_BUTTON} from '#/main/app/buttons'
import {hasPermission} from '#/main/app/security'
import {trans, transChoice} from '#/main/app/intl/translation'

import {UserCard} from '#/main/community/user/components/card'

/**
* Report action.
*/
export default (users, refresher) => {
const processable = users.filter(user => hasPermission('administrate', user) && !get(user, 'restrictions.disabled', false))

return {
name: 'report',
type: ASYNC_BUTTON,
icon: 'fa fa-fw fa-flag',
label: trans('report', {}, 'actions'),
displayed: 0 !== processable.length,
dangerous: true,
confirm: {
title: transChoice('user_reported_confirm_title', processable.length, {}, 'community'),
subtitle: 1 === processable.length ? processable[0].name : transChoice('count_elements', processable.length, {count: processable.length}),
message: transChoice('user_reported_confirm_message', processable.length, {count: processable.length}, 'community'),
additional: [
createElement('div', {
key: 'additional',
className: 'modal-body'
}, processable.map(user => createElement(UserCard, {
key: user.id,
orientation: 'row',
size: 'xs',
data: user
})))
]
},
request: {
url: url(['apiv2_user_report'], {ids: users.map(u => u.id)}),
request: {
method: 'PUT'
},
success: (response) => refresher.update(response)
},
scope: ['object', 'collection'],
group: trans('management')
}
}
3 changes: 2 additions & 1 deletion src/main/community/Resources/modules/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ registry.add('ClarolineCommunityBundle', {
'password-change': () => { return import(/* webpackChunkName: "community-action-user-password-change" */ '#/main/community/actions/user/password-change') },
'password-reset' : () => { return import(/* webpackChunkName: "community-action-user-password-reset" */ '#/main/community/actions/user/password-reset') },
'view-as' : () => { return import(/* webpackChunkName: "community-action-user-view-as" */ '#/main/community/actions/user/view-as') },
'delete' : () => { return import(/* webpackChunkName: "community-action-user-delete" */ '#/main/community/actions/user/delete') }
'delete' : () => { return import(/* webpackChunkName: "community-action-user-delete" */ '#/main/community/actions/user/delete') },
'report' : () => { return import(/* webpackChunkName: "community-action-user-report" */ '#/main/community/actions/user/report') }
},

group: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {constants as toolConstants} from '#/main/core/tool/constants'
import {EditorProfile} from '#/main/community/tools/community/editor/containers/profile'
import {EditorParameters} from '#/main/community/tools/community/editor/containers/parameters'
import {CommunityEditorActions} from '#/main/community/tools/community/editor/components/actions'
import {CommunityEditorReported} from '#/main/community/tools/community/editor/components/reported'

const CommunityEditor = (props) =>
<ToolEditor
Expand All @@ -21,6 +22,11 @@ const CommunityEditor = (props) =>
help: trans('Ajoutez des champs personnalisés pour enrichir le profil de vos utilisateurs.'),
component: EditorProfile,
disabled: props.contextType !== toolConstants.TOOL_DESKTOP
}, {
name: 'reported',
title: trans('user_reported', {}, 'community'),
help: trans('user_reported_help', {}, 'community'),
component: CommunityEditorReported
}
]}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react'

import {trans} from '#/main/app/intl'
import {EditorPage} from '#/main/app/editor'

import {UserList} from '#/main/community/user/components/list'
import {selectors} from '#/main/community/tools/community/editor/store/selectors'

const CommunityEditorReported = () =>
<EditorPage
title={trans('user_reported', {}, 'community')}
help={trans('user_reported_help', {}, 'community')}
>
<UserList
name={selectors.FORM_NAME}
url={['apiv2_user_list_reported']}
/>
</EditorPage>

export {
CommunityEditorReported
}
3 changes: 2 additions & 1 deletion src/main/community/Resources/translations/actions.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"fill": "Fill",
"empty": "Empty",
"show_activity": "Show activity",
"choose_role": "Choose a role for users/groups"
"choose_role": "Choose a role for users/groups",
"report": "Report"
}
3 changes: 2 additions & 1 deletion src/main/community/Resources/translations/actions.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"fill": "Remplir",
"empty": "Vider",
"show_activity": "Voir l'activité",
"choose_role": "Choisir le rôle auquel inscrire les utilisateurs/groupes"
"choose_role": "Choisir le rôle auquel inscrire les utilisateurs/groupes",
"report": "Signaler"
}
4 changes: 4 additions & 0 deletions src/main/community/Resources/translations/community.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
"user_delete_confirm_message": "{1} Are you sure you want to delete this user? | [2,Inf[ Are you sure you want to delete these %count% users?",
"user_disable_confirm_title": "{1} User deactivation | [2,Inf[ Users deactivation",
"user_disable_confirm_message": "{1} Are you sure you want to disable this user? | [2,Inf[ Are you sure you want to disable these %count% users?",
"user_reported_confirm_title": "{1} User reported | [2,Inf[ Users reported",
"user_reported_confirm_message": "{1} Are you sure you want to report this user? | [2,Inf[ Are you sure you want to report these %count% users?",
"user_reported": "Reported users",
"user_reported_help": "List of reported users.",
"new_user": "New user",
"user_disabled": "Inactive user",
"disable_inactive_users": "Disable inactive users",
Expand Down
4 changes: 4 additions & 0 deletions src/main/community/Resources/translations/community.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
"user_delete_confirm_message": "{1} Êtes-vous sûr de vouloir supprimer cet utilisateur ? | [2,Inf[ Êtes-vous sûr de vouloir supprimer ces %count% utilisateurs ?",
"user_disable_confirm_title": "{1} Désactivation d'un utilisateur | [2,Inf[ Désactivation de plusieurs utilisateurs",
"user_disable_confirm_message": "{1} Êtes-vous sûr de vouloir désactiver cet utilisateur ? | [2,Inf[ Êtes-vous sûr de vouloir désactiver ces %count% utilisateurs ?",
"user_reported_confirm_title": "{1} Signalement d'un utilisateur | [2,Inf[ Signalement de plusieurs utilisateurs",
"user_reported_confirm_message": "{1} Êtes-vous sûr de vouloir signaler cet utilisateur ? | [2,Inf[ Êtes-vous sûr de vouloir signaler ces %count% utilisateurs ?",
"user_reported": "Utilisateurs signalés",
"user_reported_help": "Liste des utilisateurs signalés.",
"new_user": "Nouvel utilisateur",
"user_disabled": "Utilisateur inactif",
"disable_inactive_users": "Désactiver les utilisateurs inactifs",
Expand Down
2 changes: 2 additions & 0 deletions src/main/community/Serializer/UserSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public function serialize(User $user, array $options = []): array
];
}, $user->getGroupRoles()),
),
'reported' => $user->isReported(),
];

if (!in_array(SerializerInterface::SERIALIZE_LIST, $options)) {
Expand Down Expand Up @@ -175,6 +176,7 @@ public function deserialize(array $data, User $user, array $options = []): User
$this->sipe('picture', 'setPicture', $data, $user);
$this->sipe('thumbnail', 'setThumbnail', $data, $user);
$this->sipe('poster', 'setPoster', $data, $user);
$this->sipe('reported', 'setReported', $data, $user);

// don't trim the password just in case
$this->sipe('plainPassword', 'setPlainPassword', $data, $user, false);
Expand Down
15 changes: 15 additions & 0 deletions src/main/core/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ class User extends AbstractRoleSubject implements UserInterface, EquatableInterf
*/
private ?string $status = null;

/**
* @ORM\Column(name="reported", type="boolean")
*/
private bool $reported = false;

public function __construct()
{
parent::__construct();
Expand Down Expand Up @@ -804,4 +809,14 @@ public function getLastActivity(): ?\DateTimeInterface
{
return $this->lastActivity;
}

public function isReported(): bool
{
return $this->reported;
}

public function setReported(bool $reported): void
{
$this->reported = $reported;
}
}
30 changes: 30 additions & 0 deletions src/main/core/Installation/Migrations/Version20241018125139.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Claroline\CoreBundle\Installation\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated migration based on mapping information: modify it with caution.
*
* Generation date: 2024/10/18 12:51:41
*/
final class Version20241018125139 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->addSql('
ALTER TABLE claro_user
ADD reported TINYINT(1) NOT NULL
');
}

public function down(Schema $schema): void
{
$this->addSql('
ALTER TABLE claro_user
DROP reported
');
}
}
8 changes: 8 additions & 0 deletions src/main/core/Manager/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ public function disable(User $user): User
return $user;
}

public function report(User $user): void
{
$user->setReported(true);

$this->om->persist($user);
$this->om->flush();
}

public function disableInactive(\DateTimeInterface $lastActivity): void
{
$this->messageBus->dispatch(new DisableInactiveUsers($lastActivity));
Expand Down

0 comments on commit 2ef5377

Please sign in to comment.