Skip to content

Commit 1ae5bc9

Browse files
authored
Merge pull request #50 from onozaty/feature/49-always_generate_api_key
#49 Add option to always generate API key
2 parents 0f79cbd + 7403d6f commit 1ae5bc9

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<p>
2+
<label for="settings_create_api_access_key"><%= l(:option_create_api_access_key) %></label>
3+
<%= check_box_tag 'settings[create_api_access_key]', 1, @settings[:create_api_access_key] %>
4+
</p>

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ en:
2121
field_author: "Author"
2222
text_path_pattern_info: "Path pattern is specified with a regular expression. (ex. /issues/[0-9]+)"
2323
text_path_pattern_match_info: "If there is a match with the path of the page, insert the following code and execute it."
24+
option_create_api_access_key: "Automatically create API access key"

config/locales/ja.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ ja:
2020
field_author: "作成者"
2121
text_path_pattern_info: "パスのパターンは正規表現で指定します。 (例 /issues/[0-9]+)"
2222
text_path_pattern_match_info: "ページのパスが一致した場合、以下のコードを挿入し、実行します。"
23+
option_create_api_access_key: "APIアクセスキーを自動的に作成する"

init.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
:caption => :label_view_customize,
1313
:html => { :class => 'icon icon-view_customize'},
1414
:if => Proc.new { User.current.admin? }
15-
15+
16+
settings :default => { 'create_api_access_key' => '' }, :partial => 'settings/view_customize_settings'
17+
1618
should_be_disabled false if Redmine::Plugin.installed?(:easy_extensions)
1719
end
1820

lib/view_customize/view_hook.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ def to_html(view_customize)
7777
def create_view_customize_context(view_hook_context)
7878

7979
user = User.current
80+
81+
if Setting.plugin_view_customize[:create_api_access_key] == "1" and user.api_token.nil?
82+
# Create API access key
83+
user.api_key
84+
end
85+
8086
context = {
8187
"user" => {
8288
"id" => user.id,

0 commit comments

Comments
 (0)