Discourse Category Lockdown

Very easy to configure and I think I have it working properly.

Random question, is it possible to inject a custom icon? i.e. a site logo to use as the icon instead of the font awesome icons? I currently only have it as a png

1 Like

It’s something you can do with some css, I made something similar, but I didn’t keep the code.

If I remember correctly, you need two steps: hiding the custom icon, I used the star icon in my custom theme, then add the custom image before the title

.topic-list .category-idofyourcategory {
    .topic-status .d-icon-star {
        display: none;
    }
    .title::before {
        content: url("/your_image.png");
    }
}

I didn’t reproduce it, so you might need to adjust a few things, but it should give you some direction

4 Likes

I’m re-directing to a WordPress page (my OAuth provider) which allows the user to sign up for a subscription to view the content, or just login.

The issue is that if they login and go back to the forum, they are not automatically logged into the forum (and have to click the Login button again on the forum). What do I need to change to try to make sure they are automatically logged in? Is there something I can add to my link?

If it allows you to redirect to a url you will want to add this to the end of your discourse url /session/sso?return_path=/top, you can change the path it redirects to, but this should log them in for you.

2 Likes

Outstanding! I used to be able to do this on Xenforo, so I was hoping there would be something similar on Discourse. It’s ideal for paid communities to pull folks into premium portions of the forum.

Many thanks,
Ray

P.S. @davidkingham David, took a gander at your community. It’s one of the best I have seen. Props and thanks for sharing.

Ray

2 Likes

This plugin appears to break in 2.6 beta 2. @fzngagan Discourse doesn’t allow me to load any topics when it is activated, see errors below.

Message (204 copies reported)

ArgumentError (wrong number of arguments (given 1, expected 0))
lib/topic_view.rb:59:in `initialize'
app/controllers/topics_controller.rb:81:in `new'
app/controllers/topics_controller.rb:81:in `show'
app/controllers/application_controller.rb:340:in `block in with_resolved_locale'
app/controllers/application_controller.rb:340:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:68:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:334:in `call'
config/initializers/100-quiet_logger.rb:23:in `call'
config/initializers/100-silence_logger.rb:31:in `call'
lib/middleware/enforce_hostname.rb:22:in `call'
lib/middleware/request_tracker.rb:176:in `call'

Backtrace

plugins/discourse-category-lockdown/plugin.rb:41:in `check_and_raise_exceptions'
lib/topic_view.rb:59:in `initialize'
app/controllers/topics_controller.rb:81:in `new'
app/controllers/topics_controller.rb:81:in `show'
actionpack (6.0.3.2) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (6.0.3.2) lib/abstract_controller/base.rb:195:in `process_action'
actionpack (6.0.3.2) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (6.0.3.2) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (6.0.3.2) lib/active_support/callbacks.rb:112:in `block in run_callbacks'
app/controllers/application_controller.rb:340:in `block in with_resolved_locale'

Env
1 Like

This was also on my list of things to figure out. It seems it was broken by this change (4 days ago)

https://github.com/discourse/discourse/commit/3b55de90e517f7081006947cc4fabbe5651a65c0#diff-456750b7ffa76d2d60b7bb0b60cb21e6R786

5 Likes

Thanks @RGJ for pointing out the cause.
I’ll make it a priority and look at this one in my morning time.

4 Likes

@davidkingham @RGJ, @dylanb
Just pushed a fix. Please update and confirm.

5 Likes

@fzngagan Looks like it is working properly. Thanks for the quick fix.

4 Likes

Although the plugin does not crash now, it does not function on tests-passed anymore.

The icon shows but you can access topics within a category as normal.

Just tested this by having a working plugin on 2.5, then moving to tests passed broke it.

Edit this seems like a multisite issue. The check_and_raise_exceptions function is only prepended when the plugin is enabled on multisite master. Also, Discourse needs to be restarted after enabling the plugin.

3 Likes

I’ve got a question and a request.

Question: how hard would it be to allow crawlers to see the content? I can’t seem to find a way of accessing whether the request is made by a crawler (or the user agent string) from within the guardian for anonymous users. Does anyone have any pointers? I would be happy to create a PR for it if only I knew how to get to this information.

Request: @fzngagan could you please take a look at the multisite issue that was recently introduced? I could make a PR although it would be a trivial change.

2 Likes

If you disable javascript in your browser, you can see the crawler layout (hence your users can too :wink: ).
I’ve made a POC branch named crawl which you can test and enchance. If it works, we’ll put it behind a site setting that will be off by default.

Note: I’ve not tested the branch but happy to help :slight_smile:

I would be happy to accept a PR here. Not familiar with multisite stuff yet :slight_smile:

2 Likes

I’ve made the pull request.

1 Like

Upgraded to the 2.6.0.beta5 version of Discourse and am having another issue with this plugin it looks like. Any ideas @fzngagan?.

When I try to navigate to a “locked down category” as a non-logged in user, I just get a spinning indicator (and am never redirected). It looks like it is adding “You are not permitted to view the requested resource” the URL as well.

Here are the example threads:

1 Like

Anyone have any ideas here?

1 Like

@dylanb
Yes, I realize this has been broken for some time now and is due a refactor. I’ll take a look at the end of this week most probably.

2 Likes

Ok – great. Thanks!

1 Like

@dylanb
Here’s my PR for the fix. I’ve asked for a review from @RGJ before merging it in.

https://github.com/paviliondev/discourse-category-lockdown/pull/10

4 Likes

Awesome – can you post on here when it has been merged in?

1 Like