Skip to content
15 changes: 14 additions & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ ViewCustomize = {
"admin": true,
"firstname": "Redmine",
"lastname": "Admin",
"lastLoginOn": "2019-09-22T14:44:53Z",
"groups": [
{"id": 5, "name": "Group1"}
],
Expand Down Expand Up @@ -122,7 +123,19 @@ ViewCustomize = {
}
```

例えばユーザのAPIキーにアクセスするには`ViewCustomize.context.user.apiKey`となります。
例えばユーザのAPIアクセスキーにアクセスするには`ViewCustomize.context.user.apiKey`となります。

### APIアクセスキー

APIアクセスキーは、個人設定画面のAPIアクセスキーの「表示」リンクを初めて押下したタイミングで生成されます。

![Screenshot of my account](screenshots/my_account.en.png)

自動的に生成したい場合には、プラグインの設定画面にて「APIアクセスキーを自動的に作成する」をONにしてください。各ユーザに個人設定画面で操作してもらわなくても、APIアクセスキーが生成されるようになります。

![Screenshot of plugin configure](screenshots/plugin_configure.en.png)

APIアクセスキーの利用には、設定画面の「API」タブにて、「RESTによるWebサービスを有効にする」をONにしておく必要があります。

## 設定例

Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ ViewCustomize = {
"admin": true,
"firstname": "Redmine",
"lastname": "Admin",
"lastLoginOn": "2019-09-22T14:44:53Z",
"groups": [
{"id": 5, "name": "Group1"}
],
Expand Down Expand Up @@ -128,7 +129,19 @@ ViewCustomize = {
}
```

For example, to access the user's API key is `ViewCustomize.context.user.apiKey`.
For example, to access the user's API access key is `ViewCustomize.context.user.apiKey`.

### API access key

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.

![Screenshot of my account](screenshots/my_account.en.png)

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.

![Screenshot of plugin configure](screenshots/plugin_configure.en.png)

To use the API access key, "Enable REST web service" must be turned on in the "API" tab of the setting page.

## Examples

Expand Down
5 changes: 5 additions & 0 deletions app/views/settings/_view_customize_settings.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>
<label for="settings_create_api_access_key"><%= l(:option_create_api_access_key) %></label>
<%= hidden_field_tag 'settings[create_api_access_key]', '0' %>
<%= check_box_tag 'settings[create_api_access_key]', '1', @settings[:create_api_access_key] == '1' %>
</p>
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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アクセスキーを自動的に作成する"
6 changes: 4 additions & 2 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
name 'View Customize plugin'
author 'onozaty'
description 'View Customize plugin for Redmine'
version '2.4.0'
version '2.5.0'
url 'https://github.com/onozaty/redmine-view-customize'
author_url 'https://github.com/onozaty'

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

Expand Down
9 changes: 9 additions & 0 deletions lib/view_customize/view_hook.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'time'

module RedmineViewCustomize
class ViewHook < Redmine::Hook::ViewListener
def view_layouts_base_html_head(context={})
Expand Down Expand Up @@ -75,13 +77,20 @@ 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,
"login" => user.login,
"admin" => user.admin?,
"firstname" => user.firstname,
"lastname" => user.lastname,
"lastLoginOn" => (user.last_login_on.iso8601 unless user.last_login_on.nil?),
"groups" => user.groups.map {|group| { "id" => group.id, "name" => group.name }},
"apiKey" => (user.api_token.value unless user.api_token.nil?),
"customFields" => user.custom_field_values.map {|field| { "id" => field.custom_field.id, "name" => field.custom_field.name, "value" => field.value }}
Expand Down
Binary file added screenshots/my_account.en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/plugin_configure.en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.