-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
extend.php
97 lines (82 loc) · 4.21 KB
/
extend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/*
* This file is part of fof/terms.
*
* Copyright (c) FriendsOfFlarum.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FoF\Terms;
use Flarum\Api\Controller\ShowForumController;
use Flarum\Api\Serializer\BasicUserSerializer;
use Flarum\Api\Serializer\ForumSerializer;
use Flarum\Database\AbstractModel;
use Flarum\Extend;
use Flarum\Gdpr\Extend\UserData;
use Flarum\User\User;
use FoF\Terms\Middlewares\RegisterMiddleware;
use FoF\Terms\Repositories\PolicyRepository;
use FoF\Terms\Serializers\PolicySerializer;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
return [
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js')
->css(__DIR__.'/resources/less/admin.less'),
(new Extend\Frontend('forum'))
->js(__DIR__.'/js/dist/forum.js')
->css(__DIR__.'/resources/less/forum.less'),
new Extend\Locales(__DIR__.'/resources/locale'),
(new Extend\Routes('api'))
->post('/fof/terms/policies/order', 'fof.terms.api.policies.order', Controllers\PolicyOrderController::class)
->get('/fof/terms/policies', 'fof.terms.api.policies.index', Controllers\PolicyIndexController::class)
->post('/fof/terms/policies', 'fof.terms.api.policies.store', Controllers\PolicyStoreController::class)
->patch('/fof/terms/policies/{id:[0-9]+}', 'fof.terms.api.policies.update', Controllers\PolicyUpdateController::class)
->delete('/fof/terms/policies/{id:[0-9]+}', 'fof.terms.api.policies.delete', Controllers\PolicyDeleteController::class)
->post('/fof/terms/policies/{id:[0-9]+}/accept', 'fof.terms.api.policies.accept', Controllers\PolicyAcceptController::class)
->post('/fof/terms/policies/{id:[0-9]+}/decline', 'fof.terms.api.policies.decline', Controllers\PolicyDeclineController::class)
->get('/fof/terms/policies/{id:[0-9]+}/export.{format:json|csv}', 'fof.terms.api.policies.export', Controllers\PolicyExportController::class),
(new Extend\Middleware('forum'))
->add(RegisterMiddleware::class),
(new Extend\Model(User::class))
->relationship('fofTermsPolicies', function (AbstractModel $user): BelongsToMany {
return $user->belongsToMany(Policy::class, 'fof_terms_policy_user')->withPivot('accepted_at');
})
->relationship('fofTermsPoliciesState', function (AbstractModel $user): BelongsToMany {
return $user->belongsToMany(Policy::class, 'fof_terms_policy_user')->withPivot('is_accepted');
}),
(new Extend\User())
->permissionGroups(function ($actor, $groupIds) {
return PermissionGroupProcessor::process($actor, $groupIds);
}),
(new Extend\Policy())
->modelPolicy(Policy::class, Access\PolicyPolicy::class)
->modelPolicy(User::class, Access\UserPolicy::class),
(new Extend\ApiSerializer(BasicUserSerializer::class))
->attributes(Extenders\UserPoliciesRelationship::class),
(new Extend\Settings())
->serializeToForum('fof-terms.signup-legal-text', 'fof-terms.signup-legal-text')
->serializeToForum('fof-terms.hide-updated-at', 'fof-terms.hide-updated-at', 'boolVal')
->serializeToForum('fof-terms.date-format', 'fof-terms.date-format', function ($value) {
return $value ?: 'YYYY-MM-DD';
}),
(new Extend\ApiSerializer(ForumSerializer::class))
->attribute('fof-terms.canSeeUserPoliciesState', function (ForumSerializer $serializer) {
return $serializer->getActor()->can('fof-terms.see-user-policies-state');
})
->hasMany('fofTermsPolicies', PolicySerializer::class),
(new Extend\ApiController(ShowForumController::class))
->prepareDataForSerialization(function (ShowForumController $controller, &$data) {
/**
* @var PolicyRepository $policies
*/
$policies = resolve(PolicyRepository::class);
$data['fofTermsPolicies'] = $policies->all();
})
->addInclude('fofTermsPolicies'),
(new Extend\Conditional())
->whenExtensionEnabled('flarum-gdpr', fn () => [
(new UserData())
->addType(Data\UserPolicyData::class),
]),
];