Skip to content

Commit

Permalink
Update for Flarum beta 16
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkwinkelmann committed Apr 4, 2021
1 parent 2732922 commit 7c84e34
Show file tree
Hide file tree
Showing 28 changed files with 1,051 additions and 1,053 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019-2020 Clark Winkelmann
Copyright (c) 2019-2021 Clark Winkelmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@
"type": "flarum-extension",
"license": "MIT",
"require": {
"flarum/core": ">=0.1.0-beta.14 <0.1.0-beta.15",
"flarum/core": "^0.1.0-beta.16",
"ext-json": "*"
},
"authors": [
{
"name": "Clark Winkelmann",
"email": "clark.winkelmann@gmail.com",
"homepage": "https://clarkwinkelmann.com/",
"role": "Developer"
}
],
"support": {
"source": "https://github.com/clarkwinkelmann/flarum-ext-carving-contest",
"forum": "https://discuss.flarum.org/d/21828"
},
"autoload": {
"psr-4": {
"ClarkWinkelmann\\CarvingContest\\": "src/"
Expand All @@ -25,6 +30,7 @@
"extra": {
"flarum-extension": {
"title": "Carving Contest",
"category": "feature",
"icon": {
"name": "fas fa-spider",
"backgroundColor": "#db5800",
Expand Down
46 changes: 39 additions & 7 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace ClarkWinkelmann\CarvingContest;

use Flarum\Api\Serializer\BasicUserSerializer;
use Flarum\Api\Serializer\ForumSerializer;
use Flarum\Api\Serializer\UserSerializer;
use Flarum\Extend;
use Flarum\Foundation\Application;
use Flarum\User\User;
use Illuminate\Contracts\Events\Dispatcher;

return [
(new Extend\Frontend('forum'))
Expand All @@ -25,10 +26,41 @@
(new Extend\Model(User::class))
->hasMany('carvingContestEntries', Entry::class),

function (Dispatcher $dispatcher, Application $app) {
$dispatcher->subscribe(Policies\EntryPolicy::class);
(new Extend\ApiSerializer(ForumSerializer::class))
->attributes(function (ForumSerializer $serializer): array {
return [
'carvingContestCanView' => $serializer->getActor()->hasPermission('carving-contest.view'),
'carvingContestCanModerate' => $serializer->getActor()->hasPermission('carving-contest.moderate'),
];
}),

$app->register(Providers\ForumAttributes::class);
$app->register(Providers\UserAttributes::class);
},
(new Extend\ApiSerializer(UserSerializer::class))
->attributes(function (UserSerializer $serializer, User $user): array {
if ($serializer->getActor()->can('carving-contest.view')) {
return [
'carvingContestEntryCount' => $user->carving_contest_entry_count,
];
}

return [];
}),

(new Extend\ApiSerializer(BasicUserSerializer::class))
->attributes(function (BasicUserSerializer $serializer, User $user): array {
// Use is() instead of CurrentUserSerializer because we need this information to update with relationships as well
if ($serializer->getActor()->is($user)) {
return [
'carvingContestCouldParticipate' => $user->can('createIfNotReachedLimit', Entry::class),
'carvingContestCanParticipate' => $user->can('create', Entry::class),
];
}

return [];
}),

(new Extend\Policy())
->modelPolicy(Entry::class, Policies\EntryPolicy::class),

(new Extend\Filter(Filters\EntryFilterer::class))
->addFilter(Filters\NoOpFilter::class),
];
2 changes: 1 addition & 1 deletion js/dist/admin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/dist/admin.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 7c84e34

Please sign in to comment.