This repository has been archived by the owner on Jan 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
init.rb
52 lines (44 loc) · 2.12 KB
/
init.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true
require 'redmine'
require_relative 'app/models/global_banner'
require 'banners/application_hooks'
# NOTE: Keep error message for a while to support Redmine3.x users.
def banner_version_message(original_message = nil)
<<-"USAGE"
==========================
#{original_message}
If you use Redmine3.x, please use Redmine Banner version 0.1.x or clone via
'v0.1.x-support-Redmine3' branch.
You can download older version from here: https://github.com/akiko-pusu/redmine_banner/releases
==========================
USAGE
end
def banner_admin?
GlobalBanner.banner_admin?(User.current)
end
def project_menu_allowed?
proc { |p| User.current.allowed_to?({ controller: 'banner', action: 'show' }, p) }
end
Redmine::Plugin.register :redmine_banner do
begin
name 'Redmine Banner plugin'
author 'Akiko Takano'
author_url 'http://twitter.com/akiko_pusu'
description 'Plugin to show site-wide message, such as maintenacne informations or notifications.'
version '0.3.4'
requires_redmine version_or_higher: '4.0'
url 'https://github.com/akiko-pusu/redmine_banner'
settings partial: nil, default: GlobalBanner::GLOBAL_BANNER_DEFAULT_SETTING
menu :admin_menu, 'icon redmine_banner', { controller: 'global_banner', action: 'show', "id": nil }, caption: :banner
menu :top_menu, :redmine_banner, { controller: 'global_banner', action: 'show', "id": nil }, caption: :banner,
last: true,
if: proc { banner_admin? }
menu :project_menu, :banner, { controller: 'banner', action: 'show', "id": nil },
caption: :banner, param: :project_id, after: :settings, if: project_menu_allowed?
project_module :banner do
permission :manage_banner, { banner: %I[show edit project_banner_off] }, require: :member
end
rescue ::Redmine::PluginRequirementError => e
raise ::Redmine::PluginRequirementError.new(banner_version_message(e.message)) # rubocop:disable Style/RaiseArgs
end
end