Overriding user_guardian.rb in a plugin (no fork necessary!)

It’s always more efficient and safer to develop and test on a dev build and then deploy to Production later.

The advantage of plugins is they are easily switched in and out. On dev you don’t even have to rebuild, just restart the server after changes.

3 Likes

The former, but thanks for the concern.

1 Like

It wasn’t concern! It was hope that you did the latter and got away with it, as that is my inclination despite the wise advice against it :slight_smile:

1 Like

I intend to revitalize the subject; however, with the latest update, I integrated the AI plugin, and upon switching to the core system, the modifications I made were lost. How might I implement a solution similar to this?

I need to modify this file: discourse/plugins/discourse-ai/assets/javascripts/discourse/services/ai-bot-conversations-hidden-submit.js at main · discourse/discourse · GitHub

Currently, when users send messages via AI, I publish them as regular topics.

Why? I greatly appreciate the design of asking questions through AI, as it is highly convenient. We do not waste time selecting titles or categories. I want users to easily just ask their questions (hopefully, one day Discourse will support this design for creating new topics).

Thanks

If you forked the ai plugin then you can include your fork the way you did before by adding a

 rm - rf discourse-ai

Before you clone it.

Thank you. How can I ensure that the AI plugin receives updates? I do not wish to miss out on new features. Previously, I approved each change individually and then reconfigured the settings accordingly. This way, the plugin remains current. Thank you.

That would be exactly the same.

All I suggested is a way that you can continue to use your fork instead of what is now included in core. You’ll add one line to your app.yml and everything else is exactly the same as it’s ever been.

I was unable to succeed; each attempt resulted in an error. I entered the code into the container and tried to run it, but it did not work (rm -rf plugins/discourse-ai). I added it to the app.yml file as well, yet it still did not resolve the issue.

Could you please kindly explain the exact steps I should follow in a simple manner? Thank you.

This is in your app.yml.

## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git
          - rm -rf discourse-ai
          - git clone https://github.com/your-user/discourse-ai

If you wanted to do it by hand in the container you’d do this:

./launcher enter app
cd /var/www/discourse/plugins
rm -rf discourse-ai
git clone https://github.com/your-user/discourse-ai
sv restart unicorn

If you do this it’ll be erased the next time you start a new container.

1 Like

I attempted the initial method for app.yml, yet the error I encountered remains identical to the previous one:

FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process::Status: pid 857 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.3.0/gems/pups-1.3.0/lib/pups/exec_command.rb:131:in `spawn'
exec failed with the params {"cd"=>"$home", "tag"=>"migrate", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migrate'"]}
bootstrap failed with exit code 1
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.

I am investing your time for someone simple, and I feel ashamed to ask for help, but if I succeed in this, I will feel at ease, believe me.