Skip to content

Commit cb277b3

Browse files
authored
Redmine 6 (#98)
1 parent 479dd6a commit cb277b3

File tree

11 files changed

+137
-137
lines changed

11 files changed

+137
-137
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Version: 0.6.0
2+
### Improvements
3+
- [Redmine 6.0 compatibility.](https://github.com/noshutdown-ru/vault/issues/96)
4+
15
## Version: 0.5.0
26
### Improvements
37
- [Redmine 5.0 compatibility.](https://github.com/noshutdown-ru/vault/issues/91)

Gemfile

-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ source 'https://rubygems.org'
22

33
gem 'roo'
44
gem 'iconv'
5-
gem 'rubyzip', '~> 2.3.0'
65
gem 'zip-zip'
7-
gem 'protected_attributes_continued', '1.8.2'
86

97
group :test, :development do
108
gem 'byebug'
119
gem 'capybara-screenshot'
1210
end
13-
+15-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
class KeyFilesController < ApplicationController
2-
unloadable
3-
4-
before_action :find_project_by_project_id
5-
before_action :authorize
2+
before_action :find_project_by_project_id
3+
before_action :authorize
64

7-
def download
8-
find_key
9-
unless @key.nil?
10-
send_file "#{Vault::KEYFILES_DIR}/#{@key.file}", filename: @key.name
11-
end
12-
end
13-
14-
def find_key
15-
@key = Vault::KeyFile.find(params[:id])
16-
unless @key.project_id == @project.id
17-
redirect_to project_keys_path(@project), alert: t('alert.key.not_found')
18-
@key = nil
19-
end
20-
end
5+
def download
6+
find_key
7+
unless @key.nil?
8+
send_file "#{Vault::KEYFILES_DIR}/#{@key.file}", filename: @key.name
9+
end
10+
end
2111

12+
def find_key
13+
@key = Vault::KeyFile.find(params[:id])
14+
unless @key.project_id == @project.id
15+
redirect_to project_keys_path(@project), alert: t('alert.key.not_found')
16+
@key = nil
17+
end
18+
end
2219
end

app/controllers/keys_controller.rb

+27-31
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
class KeysController < ApplicationController
2-
unloadable
3-
42
before_action :find_project_by_project_id, except: [:all]
53
before_action :authorize, except: [:all]
6-
before_action :find_key, only: [ :show, :edit, :update, :destroy, :copy ]
7-
before_action :find_keys, only: [ :context_menu ]
4+
before_action :find_key, only: [:show, :edit, :update, :destroy, :copy]
5+
before_action :find_keys, only: [:context_menu]
86
accept_api_auth :index, :show
97

108
helper :sort
119
include SortHelper
1210
helper ContextMenusHelper
1311

1412
def index
15-
1613
unless Setting.plugin_vault['use_redmine_encryption'] ||
17-
Setting.plugin_vault['use_null_encryption']
14+
Setting.plugin_vault['use_null_encryption']
1815
if not Setting.plugin_vault['encryption_key'] or Setting.plugin_vault['encryption_key'].empty?
1916
render_error t("error.key.not_set")
2017
return
@@ -39,8 +36,8 @@ def index
3936
end
4037

4138
@keys = @keys.order(sort_clause) unless @keys.nil?
42-
@keys = @keys.select { |key| key.whitelisted?(User,@project) } unless @keys.nil?
43-
@keys = [] if @keys.nil? #hack for decryption
39+
@keys = @keys.select { |key| key.whitelisted?(User.current, @project) } unless @keys.nil?
40+
@keys = [] if @keys.nil? # hack for decryption
4441

4542
@limit = per_page_option
4643
@key_count = @keys.count
@@ -61,7 +58,7 @@ def index
6158
end
6259

6360
def all
64-
unless User.current.allowed_to?({:controller => 'keys', :action => 'all'}, nil, :global => true)
61+
unless User.current.allowed_to?({ :controller => 'keys', :action => 'all' }, nil, :global => true)
6562
render_error t("error.user.not_allowed")
6663
return
6764
end
@@ -97,8 +94,8 @@ def all
9794
end
9895

9996
@keys = @keys.order(sort_clause) unless @keys.nil?
100-
@keys = @keys.select { |key| key.whitelisted?(User,key.project) } unless @keys.nil?
101-
@keys = [] if @keys.nil? #hack for decryption
97+
@keys = @keys.select { |key| key.whitelisted?(User.current, key.project) } unless @keys.nil?
98+
@keys = [] if @keys.nil? # hack for decryption
10299

103100
@limit = per_page_option
104101
@key_count = @keys.count
@@ -131,12 +128,11 @@ def copy
131128

132129
def create
133130
save_file if key_params[:file]
134-
@key = Vault::Key.new(key_params)
135-
131+
@key = Vault::Key.new
132+
@key.safe_attributes = key_params.except(:tags)
133+
@key.tags = key_params[:tags]
136134
@key.project = @project
137-
138-
@key.tags = Vault::Tag.create_from_string(key_params[:tags])
139-
135+
140136
self.update_wishlist
141137

142138
respond_to do |format|
@@ -151,48 +147,48 @@ def create
151147
def update
152148
save_file if key_params[:file]
153149
respond_to do |format|
154-
155150
self.update_wishlist
151+
@key.safe_attributes = key_params.except(:tags)
156152

157-
if @key.update(params[:vault_key])
158-
@key.tags = Vault::Tag.create_from_string(key_params[:tags])
153+
if @key.update(key_params)
154+
@key.tags = key_params[:tags]
159155
format.html { redirect_to project_keys_path(@project), notice: t('notice.key.update.success') }
160156
else
161-
format.html { render action: 'edit'}
157+
format.html { render action: 'edit' }
162158
end
163159
end
164160
end
165161

166162
def update_wishlist
167163
if User.current.allowed_to?(:manage_whitelist_keys, @key.project)
168164
if params[:whitelist].blank?
169-
@key.whitelist = ""
165+
@key.whitelist = ""
170166
else
171-
@key.whitelist = params[:whitelist].join(",")
167+
@key.whitelist = params[:whitelist].join(",")
172168
end
173169
end
174170
end
175171

176172
def edit
177-
if !@key.whitelisted?(User,@project)
173+
if !@key.whitelisted?(User.current, @project)
178174
render_error t("error.key.not_whitelisted")
179175
return
180176
else
181177
@key.decrypt!
182178
respond_to do |format|
183-
format.html { render action: 'edit'}
179+
format.html { render action: 'edit' }
184180
end
185181
end
186182
end
187183

188184
def show
189-
if !@key.whitelisted?(User,@project)
185+
if !@key.whitelisted?(User.current, @project)
190186
render_error t("error.key.not_whitelisted")
191187
return
192188
else
193189
@key.decrypt!
194190
respond_to do |format|
195-
format.html { render action: 'show'}
191+
format.html { render action: 'show' }
196192
end
197193
end
198194
end
@@ -204,23 +200,23 @@ def destroy
204200
end
205201

206202
def context_menu
207-
#FIXME
203+
# FIXME
208204
@keys.map(&:decrypt!)
209205
render layout: false
210206
end
211207

212208
private
213209

214210
def find_key
215-
@key=Vault::Key.find(params[:id])
211+
@key = Vault::Key.find(params[:id])
216212
unless @key.project_id == @project.id
217213
redirect_to project_keys_path(@project), notice: t('alert.key.not_found')
218214
end
219215
end
220216

221217
def find_keys
222-
@keys=Vault::Key.find(params[:ids])
223-
unless @keys.all? { |k| k.project_id == @project.id }
218+
@keys = Vault::Key.find(params[:ids])
219+
unless @keys.all? { |k| k.project_id == @project.id }
224220
redirect_to project_keys_path(@project), notice: t('alert.key.not_found')
225221
end
226222
end
@@ -239,7 +235,7 @@ def save_file
239235
params['vault_key']['file'] = name
240236
end
241237

242-
def projects_for_jump_box(user=User.current)
238+
def projects_for_jump_box(user = User.current)
243239
if user.logged?
244240
user.projects.active.select(:id, :name, :identifier, :lft, :rgt).to_a
245241
else

app/controllers/tags_controller.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ def index
88
end
99

1010
def create
11-
@tag = @key.tags.build(tag_params)
11+
@tag = @key.tags.build
12+
@tag.safe_attributes = tag_params
1213
if @tag.save
1314
redirect_to project_key_tags_path(@project, @key), notice: 'Tag was successfully created.'
1415
else
@@ -17,7 +18,8 @@ def create
1718
end
1819

1920
def update
20-
if @tag.update(tag_params)
21+
@tag.safe_attributes = tag_params
22+
if @tag.save
2123
redirect_to project_key_tags_path(@project, @key), notice: 'Tag was successfully updated.'
2224
else
2325
render :index
@@ -46,4 +48,4 @@ def find_tag
4648
def tag_params
4749
params.require(:tag).permit(:name, :color)
4850
end
49-
end
51+
end

app/controllers/vault_settings_controller.rb

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
require 'zip'
33

44
class VaultSettingsController < ApplicationController
5-
unloadable
65
menu_item :vault_settings
76

87
layout 'admin'
@@ -14,12 +13,12 @@ def index
1413

1514
def save
1615
if params[:settings][:encryption_key].length != 16 and params[:settings][:encryption_key].length != 0
17-
redirect_to vault_settings_path, :flash => { :error => t('error.key.length') }
16+
redirect_to vault_settings_path, :flash => { :error => t('error.key.length') }
1817
return
1918
end
2019

2120
Setting.send "plugin_vault=", params[:settings]
22-
redirect_to vault_settings_path , notice: t('notice.settings.saved')
21+
redirect_to vault_settings_path, notice: t('notice.settings.saved')
2322
end
2423

2524
def backup
@@ -59,8 +58,8 @@ def backup
5958
zip_data = IO.binread(tmp_fname)
6059

6160
send_data zip_data,
62-
:type => 'application/zip',
63-
:disposition => "attachment; filename=#{fname}"
61+
:type => 'application/zip',
62+
:disposition => "attachment; filename=#{fname}"
6463

6564
end
6665

0 commit comments

Comments
 (0)