v17development / flarum-blog

The Flarum Blog extension
https://discuss.flarum.org/d/25392-blog-adds-a-blog-section-to-your-community
MIT License
46 stars 20 forks source link

Pending review status issue #151

Open hepaly opened 2 years ago

hepaly commented 2 years ago

All logged in users can see blogs that have not been yet approved. (status pending review) flarum info:


PHP version: 8.1.8
MySQL version: 5.7.38-0ubuntu0.18.04.1
Loaded extensions: Core, date, libxml, openssl, pcre, zlib, filter, hash, json, pcntl, Reflection, SPL, session, standard, sodium, mysqlnd, PDO, xml, apcu, bcmath, bz2, calendar, ctype, curl, dom, mbstring, FFI, fileinfo, ftp, gd, gettext, gmp, iconv, imagick, imap, intl, exif, memcache, mysqli, pdo_mysql, pdo_sqlite, Phar, posix, pspell, readline, shmop, SimpleXML, sockets, sqlite3, sysvmsg, sysvsem, sysvshm, tidy, tokenizer, xmlreader, xmlwriter, xsl, zip, Zend OPcache
+----------------------------------+------------+------------------------------------------+
| Flarum Extensions                |            |                                          |
+----------------------------------+------------+------------------------------------------+
| ID                               | Version    | Commit                                   |
+----------------------------------+------------+------------------------------------------+
| flarum-flags                     | v1.4.0     |                                          |
| flarum-tags                      | v1.4.0     |                                          |
| flarum-lock                      | v1.4.0     |                                          |
| afrux-forum-widgets-core         | v0.1.7     |                                          |
| flarum-suspend                   | v1.4.0     |                                          |
| fof-pages                        | 1.0.4      |                                          |
| flarum-approval                  | v1.4.0     |                                          |
| zerosonesfun-up                  | 1.0        |                                          |
| v17development-seo               | v1.8.0     |                                          |
| v17development-blog              | v0.6.3     |                                          |
| ubuntuhu-map                     | dev-master | 4649dd16b2ea238c436aa31b1d3bfe23d732ed81 |
| sycho-profile-cover              | v1.3.3     |                                          |
| ralkage-hcaptcha                 | 1.0.0      |                                          |
| nearata-twofactor                | v2.0.1     |                                          |
| miniflar-admin-notepad-widget    | 1.0.0      |                                          |
| justoverclock-welcomebox         | 1.3.7      |                                          |
| justoverclock-hot-discussions    | 0.1.2      |                                          |
| justoverclock-custom-html-widget | 0.1.4      |                                          |
| ianm-syndication                 | 1.2.1      |                                          |
| fof-user-bio                     | 1.1.0      |                                          |
| fof-upload                       | 1.2.3      |                                          |
| fof-spamblock                    | 1.0.2      |                                          |
| fof-sitemap                      | 2.0.1      |                                          |
| fof-reactions                    | 1.1.2      |                                          |
| fof-polls                        | 1.1.0      |                                          |
| fof-nightmode                    | 1.4.0      |                                          |
| fof-merge-discussions            | 1.3.1      |                                          |
| fof-linguist                     | 1.0.4      |                                          |
| fof-cookie-consent               | 1.1.0      |                                          |
| fof-byobu                        | 1.1.7      |                                          |
| fof-best-answer                  | 1.2.3      |                                          |
| flarum-subscriptions             | v1.4.0     |                                          |
| flarum-sticky                    | v1.4.0     |                                          |
| flarum-statistics                | v1.4.1     |                                          |
| flarum-pusher                    | v1.4.0     |                                          |
| flarum-nicknames                 | v1.4.0     |                                          |
| flarum-mentions                  | v1.4.0     |                                          |
| flarum-markdown                  | v1.4.0     |                                          |
| flarum-likes                     | v1.4.0     |                                          |
| flarum-lang-hungarian            | v2.0.16    |                                          |
| flarum-lang-english              | v1.4.0     |                                          |
| flarum-emoji                     | v1.4.0     |                                          |
| flarum-bbcode                    | v1.4.0     |                                          |
| davwheat-custom-sidenav-links    | 1.0.1      |                                          |
| darkle-fancybox                  | 1.1.2      |                                          |
| clarkwinkelmann-group-list       | 1.0.0      |                                          |
| clarkwinkelmann-emojionearea     | 1.0.0      |                                          |
| askvortsov-pwa                   | v3.1.3     |                                          |
| antoinefr-online                 | v1.0.1     |                                          |
| afrux-forum-stats-widget         | v0.1.1     |                                          |
| acpl-mobile-tab                  | 1.1.0      |                                          |
+----------------------------------+------------+------------------------------------------+```
The result is the same after I upgraded to v.0.6.4.
Thanks
hepaly commented 2 years ago

I don't know what is the best solution, but its working with this modification bellow :) vendor/v17development/flarum-blog/src/Access/ScopeDiscussionVisibility.php

<?php

namespace V17Development\FlarumBlog\Access;

use Flarum\User\User;
use Illuminate\Database\Eloquent\Builder;

class ScopeDiscussionVisibility
{
    /**
     * @param User $actor
     * @param Builder $query
     */
    public function __invoke(User $actor, Builder $query)
    {
        // Hide blogposts which arent published or are still pending approval
        // Writers will have access to the posts if they are still pending for review
        $this->actorid = $actor->id;
        if( !$actor->hasPermission('blog.canApprovePosts') ) {   
            $query->whereNotIn('discussions.id', function ($query) {
                return $query  
                    ->select('bm.discussion_id')
                    ->from('blog_meta as bm')
                    ->join('discussions as d','d.id', '=', 'bm.discussion_id','inner')
                    ->where('d.user_id', '!=',  $this->actorid)
                    ->where('bm.is_pending_review', 1);
            });
        }
    }
}