- 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.
推薦閱讀
- Intel Galileo Essentials
- 零基礎(chǔ)搭建量化投資系統(tǒng):以Python為工具
- PostgreSQL Cookbook
- SAP BusinessObjects Dashboards 4.1 Cookbook
- Mathematica Data Analysis
- Building Android UIs with Custom Views
- Python機器學(xué)習(xí):預(yù)測分析核心算法
- 速學(xué)Python:程序設(shè)計從入門到進階
- 軟件供應(yīng)鏈安全:源代碼缺陷實例剖析
- Python機器學(xué)習(xí)之金融風(fēng)險管理
- Emotional Intelligence for IT Professionals
- ASP.NET 4.0 Web程序設(shè)計
- 快樂編程:青少年思維訓(xùn)練
- 微信公眾平臺開發(fā)最佳實踐
- Django 2.0 入門與實踐