Fixed #29 and added admin menu item

This commit is contained in:
Alexander Meindl 2016-04-23 10:06:21 +02:00
parent 7fa359e7aa
commit 50e16d211b
10 changed files with 123 additions and 59 deletions

View File

@ -2,6 +2,12 @@
## Changelog
### 0.5.8-dev
- Fixed top menu items permissions for anonymous and non member #29
- Fixed bug with overwriting application handler, which cases problem with other plugins
- Tweaks link added to admin menu
### 0.5.7
- Custom source URL for Garfield source

View File

@ -9,41 +9,7 @@
<%
user_roles = User.current.memberships.collect {|m| m.roles}.flatten.uniq
5.times do |i|
menu_name = 'custom_menu'+i.to_s
url = Setting.plugin_redmine_tweaks[menu_name+'_url']
name = Setting.plugin_redmine_tweaks[menu_name+'_name']
title = Setting.plugin_redmine_tweaks[menu_name+'_title']
roles = Setting.plugin_redmine_tweaks[menu_name+'_roles']
unless name.nil? || name.empty? || url.empty? || roles.nil?
show_entry = false
roles.each do |role|
user_roles.each do |user_role|
if role.to_i == user_role.id.to_i
show_entry = true
break
end
end
if show_entry == true
break
end
end
if Redmine::MenuManager.map(:top_menu).exists?(menu_name.to_sym)
Redmine::MenuManager.map(:top_menu).delete(menu_name.to_sym)
end
if show_entry
html_options = {}
if url.include? "://"
html_options[:class] = 'external'
end
unless title.empty?
html_options[:title] = title
end
Redmine::MenuManager.map(:top_menu).push menu_name, url, :caption => name.to_s, :html => html_options, :before => :help
end
end
add_top_menu_custom_item(i, user_roles)
end
%>

BIN
assets/images/tweaks.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 914 B

View File

@ -1,4 +1,5 @@
.nodata.nodata-left { text-align: left; }
#admin-menu a.tweaks { background-image: url(../images/tweaks.png); }
/* Go to top link */
.gototop {

View File

@ -82,3 +82,4 @@ de:
messages:
issue_cannot_close_with_open_children: "Das Ticket kann nicht geschlossen werden, bevor nicht alle Untertickets geschlossen wurden."
issue_current_user_status: "Der ausgewählte Status erfordert, dass \"Zugewiesen an\" Dir selbst zugeordnet wird."
label_tweaks: Tweaks

View File

@ -82,3 +82,4 @@ en:
messages:
issue_cannot_close_with_open_children: "This issue can only be closed, if all sub-issues are closed, too."
issue_current_user_status: "The selected status requires that the \"Assignee\" is yourself."
label_tweaks: Tweaks

View File

@ -5,6 +5,7 @@ ja:
label_settings_general: "共通"
label_settings_content: "コンテンツ"
label_settings_menu: "メニュー"
label_settings_rules: "Issue rules"
label_menu_entry: "メニュー項目"
label_top_menu_help: "ここで新しいトップメニューの項目を定義出来ます。リンクの追加・削除を行った場合、ウェブサーバを再起動してください。"
label_optional: "任意"
@ -14,14 +15,18 @@ ja:
label_external_urls: "外部URL"
external_url_default: "規程の扱い"
external_url_new_window: "新しいウインドウで開く"
external_url_anonymize: "レフェラーを匿名化"
external_url_noreferrer: "レフェラーを匿名化"
external_urls_info_html: "外部URLの扱いを指定する。"
label_custom_help_url: "カスタムヘルプURL"
custom_help_url_info_html: "このURLを変更した後、反映するためにウェブサーバを再起動しなければなりません。URLの指定がない場合、規程のヘルプURLが使用されます。"
label_remove_mypage: "「マイ・ページ」をトップメニューから外す"
label_remove_help: "「ヘルプ」をトップメニューから外す"
remove_mypage_info: 'タスクボードを導入するために、「マイ・ページ」のリンクを隠した方が便利な場合があります。タスクボードにより、ステータス毎の順番並び替えに出来るメリットがあります。'
label_remove_news: "Remove 'Lastest news' from overview page"
label_remove_latest_projects: "Remove 'Lastest projects' from overview page"
label_remove_mypage: "「マイ・ページ」をトップメニューから外す"
remove_help_info: "「ヘルプ」項目をトップメニューから外す"
remove_news_info: "Remove latest news from overview page."
remove_latest_projects_info: "Remove latest projects from overview page."
remove_mypage_info: 'タスクボードを導入するために、「マイ・ページ」のリンクを隠した方が便利な場合があります。タスクボードにより、ステータス毎の順番並び替えに出来るメリットがあります。'
label_account_login: "ログイン画面の文章"
account_login_info: "この文章は、ログイン画面で表示され、登録情報の掲載を目的にしています。これらの設定は全プロジェクトで有効です。"
label_new_ticket_message: "新規チケットのメモ"
@ -41,3 +46,41 @@ ja:
global_footer_info: 'プロジェクト全体のWikiフッターをここに入力する'
label_disabled_modules: "無効化したいモジュール"
disabled_modules_info: "プロジェクト内で選択させたくないモジュール。もしこのモジュールが既存のプロジェクトで既に有効な場合、設定変更した上で、ウェブサーバを再起動しなければなりません。"
label_overview_right: "Overview page, right"
label_overview_top: "Overview page, top"
label_overview_bottom: "Overview page, bottom"
overview_right_info: "Here you can add your text, which will be shown on the overview page at the right side. For example you can link to a wiki page."
overview_top_info: "Here you can add your text, which will be shown on the overview page at the top. For example you can link to a wiki page."
overview_bottom_info: "Here you can add your text, which will be shown on the overview page at the bottom. For example you can link to a wiki page."
label_settings_macros: "Macros"
label_top_macros_help_html: "Here you get a list of all available Redmine macros of your installation, which are provided by Redmine and the Redmine plugins."
permission_hide_in_memberbox: "Hide in memberbox"
permission_show_hidden_roles_in_memberbox: "Show hidden roles in member box"
permission_edit_closed_issues: "Edit closed issues"
menu_roles_info: "Only members of selected roles will see this menu entry."
label_rule_issue_close_with_open_children: Issues with open sub-issues cannot be closed
top_rules_help: "Here you can define rules, which are used in issues of all projects."
top_content_help: "Here you can define texts, which will be displayed in diverse areas of Redmine. Use simple text, macros and wiki syntax for your content."
label_rule_issue_status_change: "If \"Assignee\" is unchanged and the issue status changed from x to y, than the author is assigned to the issue"
rule_issue_status_change_info: "Use Case: issues should be automatically assigned to autor, if the status changes to \"Approval\"."
label_rule_issue_current_user_status: "Current issue status x is only allowed if \"Assignee\" is the current user."
rule_issue_current_user_status_info: "Use Case: Users are only allowed to change the status to \"In Progress\" if they are the person who is actually working on the issue right now."
label_garfield_source: Garfield source host
garfield_source_info: "Enter the server here (only host name), by which the single comics by the use of SSL are offered. Please make sure to respect the particular terms of use and copyright laws."
minutes:
one: minute
other: minutes
hours:
one: hour
other: hours
days:
one: day
other: days
label_system_info: System info
label_uptime: Uptime
activerecord:
errors:
messages:
issue_cannot_close_with_open_children: "This issue can only be closed, if all sub-issues are closed, too."
issue_current_user_status: "The selected status requires that the \"Assignee\" is yourself."
label_tweaks: Tweaks

View File

@ -8,7 +8,7 @@ Redmine::Plugin.register :redmine_tweaks do
name 'Redmine Tweaks'
author 'AlphaNodes GmbH'
description 'Wiki and content extensions'
version '0.5.7'
version '0.5.8-dev'
author_url 'https://alphanodes.com/'
url 'https://github.com/alexandermeindl/redmine_tweaks'
@ -62,7 +62,9 @@ Redmine::Plugin.register :redmine_tweaks do
:my_page,
{ controller: 'my', action: 'page' },
via: :get,
if: proc { User.current && !RedmineTweaks.settings[:remove_mypage] }
if: proc { User.current.logged? && !RedmineTweaks.settings[:remove_mypage] }
menu :admin_menu, :tweaks, { controller: 'settings', action: 'plugin', id: 'redmine_tweaks' }, caption: :label_tweaks
RedCloth3::ALLOWED_TAGS << 'div'
end

View File

@ -52,7 +52,60 @@ module RedmineTweaks
end
view_roles
end
def add_top_menu_custom_item(i, user_roles)
menu_name = 'custom_menu' + i.to_s
item = {
url: Setting.plugin_redmine_tweaks[menu_name + '_url'],
name: Setting.plugin_redmine_tweaks[menu_name + '_name'],
title: Setting.plugin_redmine_tweaks[menu_name + '_title'],
roles: Setting.plugin_redmine_tweaks[menu_name + '_roles']
}
unless item[:name].blank? || item[:url].blank? || item[:roles].nil?
show_entry = false
item[:roles].each do |role|
if user_roles.empty? && role.to_i == Role::BUILTIN_ANONYMOUS
show_entry = true
break
elsif User.current.logged? && role.to_i == Role::BUILTIN_NON_MEMBER
# if user is logged in and non_member is active in item,
# always show it
show_entry = true
break
end
user_roles.each do |user_role|
if role.to_i == user_role.id.to_i
show_entry = true
break
end
end
break if show_entry == true
end
handle_top_menu_item(menu_name, item, show_entry)
end
end
def handle_top_menu_item(menu_name, item, show_entry = false)
if Redmine::MenuManager.map(:top_menu).exists?(menu_name.to_sym)
Redmine::MenuManager.map(:top_menu).delete(menu_name.to_sym)
end
if show_entry
html_options = {}
html_options[:class] = 'external' if item[:url].include? '://'
html_options[:title] = item[:title] unless item[:title].blank?
Redmine::MenuManager.map(:top_menu).push menu_name,
item[:url],
caption: item[:name].to_s,
html: html_options,
before: :help
end
end
end
end
ActionView::Base.send :include, RedmineTweaks::Helper
unless ActionView::Base.included_modules.include?(RedmineTweaks::Helper)
ActionView::Base.send(:include, RedmineTweaks::Helper)
end

View File

@ -11,18 +11,15 @@ module RedmineTweaks
base.class_eval do
alias_method_chain :parse_redmine_links, :tweaks
def link_to_user_static(user, display, format, only_path)
def link_to_user_static(user, display, format)
name = display || user.name(format)
if user.active?
# user_id = user.login.match(%r{^[a-z0-9_\-]+$}i) ? user.login.downcase : user
link = link_to(h(name),
# { only_path: only_path, controller: 'users', action: 'show', id: user_id },
user_path(user),
class: user.css_classes)
link_to(h(name),
user_path(user),
class: user.css_classes)
else
link = h(name)
h(name)
end
link
end
end
end
@ -63,19 +60,13 @@ module RedmineTweaks
end
if sep == '#'
oid = identifier.to_i
case prefix
when 'user'
if user = User.find_by_id(oid)
link = link_to_user_static(user, display, format, only_path)
end
if prefix == 'user' && user = User.find_by_id(oid)
link = link_to_user_static(user, display, format)
end
elsif sep == ':'
oname = identifier.gsub(%r{^"(.*)"$}, '\\1')
case prefix
when 'user'
if user = User.find_by_login(oname)
link = link_to_user_static(user, display, format, only_path)
end
if prefix == 'user' && user = User.find_by_login(oname)
link = link_to_user_static(user, display, format)
end
end
end