- Redmine Plugin Extension and Development
- Alex Bevilacqua
- 137字
- 2021-07-16 12:20:25
Controller hooks
Controller hooks allow custom functionality to be injected into an existing process. A normal use-case for this type of hook is to perform some custom validation on the context object provided to the callback.
In /path/to/redmine/app/models/issue.rb
, there is a hook registered for controller_issues_edit_before_save
. In order to take advantage of this hook, we would have to provide our own callback function. This can be done as follows:
module Knowledgebase module Hooks class ControllerIssuesEditBeforeSaveHook < Redmine::Hook::ViewListener def controller_issues_edit_before_save(context={}) if context[:params] && context[:params][:issue] if User.current.allowed_to?(:assign_article_to_issue, context[:issue].project) if context[:params][:issue][:article_id].present? article = KbArticle.find_by_id(context[:params][:issue][:article_id]) if article.category.project == context[:issue].project context[:issue].article = article end else context[:issue].article = nil end end end return '' end end end end
Once registered, this hook will check to see whether the current user has permission to attach a knowledgebase article to an issue before saving the issue.
推薦閱讀
- Getting Started with Citrix XenApp? 7.6
- HTML5+CSS3+JavaScript從入門到精通:上冊(微課精編版·第2版)
- MySQL數據庫應用與管理 第2版
- LabVIEW入門與實戰開發100例
- Python自然語言處理(微課版)
- Spring+Spring MVC+MyBatis整合開發實戰
- 量化金融R語言高級教程
- 飛槳PaddlePaddle深度學習實戰
- Linux:Embedded Development
- 軟件測試實用教程
- Sails.js Essentials
- 用Python動手學統計學
- 大話代碼架構:項目實戰版
- HTML5 Game Development by Example:Beginner's Guide(Second Edition)
- 新手學ASP.NET 3.5網絡開發