From 1b2a65ec3616d626a0a8fbe21530bbc73f83b776 Mon Sep 17 00:00:00 2001 From: onozaty Date: Sun, 29 Sep 2019 21:57:58 +0900 Subject: [PATCH 1/3] [WIP] #49 Add option to always generate API key From 113d7fa6ec629501f8f09319fa8af9d991a40dab Mon Sep 17 00:00:00 2001 From: onozaty Date: Sun, 29 Sep 2019 23:14:52 +0900 Subject: [PATCH 2/3] Add setting screen --- app/views/settings/_view_customize_settings.html.erb | 4 ++++ config/locales/en.yml | 1 + config/locales/ja.yml | 1 + init.rb | 4 +++- 4 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 app/views/settings/_view_customize_settings.html.erb diff --git a/app/views/settings/_view_customize_settings.html.erb b/app/views/settings/_view_customize_settings.html.erb new file mode 100644 index 0000000..e59b1ab --- /dev/null +++ b/app/views/settings/_view_customize_settings.html.erb @@ -0,0 +1,4 @@ +

+ + <%= check_box_tag 'settings[create_api_access_key]', 1, @settings[:create_api_access_key] %> +

diff --git a/config/locales/en.yml b/config/locales/en.yml index 42d4f1c..6cf13bb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -21,3 +21,4 @@ en: field_author: "Author" text_path_pattern_info: "Path pattern is specified with a regular expression. (ex. /issues/[0-9]+)" text_path_pattern_match_info: "If there is a match with the path of the page, insert the following code and execute it." + option_create_api_access_key: "Automatically create API access key" diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 26ac9bb..b83b51c 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -20,3 +20,4 @@ ja: field_author: "作成者" text_path_pattern_info: "パスのパターンは正規表現で指定します。 (例 /issues/[0-9]+)" text_path_pattern_match_info: "ページのパスが一致した場合、以下のコードを挿入し、実行します。" + option_create_api_access_key: "APIアクセスキーを自動的に作成する" \ No newline at end of file diff --git a/init.rb b/init.rb index 7dce344..ec4d43c 100644 --- a/init.rb +++ b/init.rb @@ -12,7 +12,9 @@ :caption => :label_view_customize, :html => { :class => 'icon icon-view_customize'}, :if => Proc.new { User.current.admin? } - + + settings :default => { 'create_api_access_key' => '' }, :partial => 'settings/view_customize_settings' + should_be_disabled false if Redmine::Plugin.installed?(:easy_extensions) end From 7403d6fc4755ab98a103e070055e7105e26086a5 Mon Sep 17 00:00:00 2001 From: onozaty Date: Tue, 1 Oct 2019 00:34:01 +0900 Subject: [PATCH 3/3] if "Automatically create API access key" option is on, create an API access key --- lib/view_customize/view_hook.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/view_customize/view_hook.rb b/lib/view_customize/view_hook.rb index 867e8ce..904a3fc 100644 --- a/lib/view_customize/view_hook.rb +++ b/lib/view_customize/view_hook.rb @@ -75,6 +75,12 @@ def to_html(view_customize) def create_view_customize_context(view_hook_context) user = User.current + + if Setting.plugin_view_customize[:create_api_access_key] == "1" and user.api_token.nil? + # Create API access key + user.api_key + end + context = { "user" => { "id" => user.id,