Skip to content

Commit 274e06d

Browse files
authored
Merge pull request #53 from onozaty/develop/2.5.0
Develop v2.5.0
2 parents 6545f21 + 1e38115 commit 274e06d

File tree

9 files changed

+48
-4
lines changed

9 files changed

+48
-4
lines changed

README.ja.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ ViewCustomize = {
9595
"admin": true,
9696
"firstname": "Redmine",
9797
"lastname": "Admin",
98+
"lastLoginOn": "2019-09-22T14:44:53Z",
9899
"groups": [
99100
{"id": 5, "name": "Group1"}
100101
],
@@ -122,7 +123,19 @@ ViewCustomize = {
122123
}
123124
```
124125

125-
例えばユーザのAPIキーにアクセスするには`ViewCustomize.context.user.apiKey`となります。
126+
例えばユーザのAPIアクセスキーにアクセスするには`ViewCustomize.context.user.apiKey`となります。
127+
128+
### APIアクセスキー
129+
130+
APIアクセスキーは、個人設定画面のAPIアクセスキーの「表示」リンクを初めて押下したタイミングで生成されます。
131+
132+
![Screenshot of my account](screenshots/my_account.en.png)
133+
134+
自動的に生成したい場合には、プラグインの設定画面にて「APIアクセスキーを自動的に作成する」をONにしてください。各ユーザに個人設定画面で操作してもらわなくても、APIアクセスキーが生成されるようになります。
135+
136+
![Screenshot of plugin configure](screenshots/plugin_configure.en.png)
137+
138+
APIアクセスキーの利用には、設定画面の「API」タブにて、「RESTによるWebサービスを有効にする」をONにしておく必要があります。
126139

127140
## 設定例
128141

README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ ViewCustomize = {
101101
"admin": true,
102102
"firstname": "Redmine",
103103
"lastname": "Admin",
104+
"lastLoginOn": "2019-09-22T14:44:53Z",
104105
"groups": [
105106
{"id": 5, "name": "Group1"}
106107
],
@@ -128,7 +129,19 @@ ViewCustomize = {
128129
}
129130
```
130131

131-
For example, to access the user's API key is `ViewCustomize.context.user.apiKey`.
132+
For example, to access the user's API access key is `ViewCustomize.context.user.apiKey`.
133+
134+
### API access key
135+
136+
The API access key is created when the "Show" link of the API access key on the My account page is click for the first time.
137+
138+
![Screenshot of my account](screenshots/my_account.en.png)
139+
140+
If you want to created it automatically, set "Automatically create API access key" to ON in the plugin configure page. API access keys can be created without having each user operate the My account page.
141+
142+
![Screenshot of plugin configure](screenshots/plugin_configure.en.png)
143+
144+
To use the API access key, "Enable REST web service" must be turned on in the "API" tab of the setting page.
132145

133146
## Examples
134147

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<p>
2+
<label for="settings_create_api_access_key"><%= l(:option_create_api_access_key) %></label>
3+
<%= hidden_field_tag 'settings[create_api_access_key]', '0' %>
4+
<%= check_box_tag 'settings[create_api_access_key]', '1', @settings[:create_api_access_key] == '1' %>
5+
</p>

config/locales/en.yml

+1
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

+1
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

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
name 'View Customize plugin'
44
author 'onozaty'
55
description 'View Customize plugin for Redmine'
6-
version '2.4.0'
6+
version '2.5.0'
77
url 'https://github.com/onozaty/redmine-view-customize'
88
author_url 'https://github.com/onozaty'
99

@@ -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

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'time'
2+
13
module RedmineViewCustomize
24
class ViewHook < Redmine::Hook::ViewListener
35
def view_layouts_base_html_head(context={})
@@ -75,13 +77,20 @@ def to_html(view_customize)
7577
def create_view_customize_context(view_hook_context)
7678

7779
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+
7886
context = {
7987
"user" => {
8088
"id" => user.id,
8189
"login" => user.login,
8290
"admin" => user.admin?,
8391
"firstname" => user.firstname,
8492
"lastname" => user.lastname,
93+
"lastLoginOn" => (user.last_login_on.iso8601 unless user.last_login_on.nil?),
8594
"groups" => user.groups.map {|group| { "id" => group.id, "name" => group.name }},
8695
"apiKey" => (user.api_token.value unless user.api_token.nil?),
8796
"customFields" => user.custom_field_values.map {|field| { "id" => field.custom_field.id, "name" => field.custom_field.name, "value" => field.value }}

screenshots/my_account.en.png

19.1 KB
Loading

screenshots/plugin_configure.en.png

6.19 KB
Loading

0 commit comments

Comments
 (0)