1
1
class KeysController < ApplicationController
2
- unloadable
3
-
4
2
before_action :find_project_by_project_id , except : [ :all ]
5
3
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 ]
8
6
accept_api_auth :index , :show
9
7
10
8
helper :sort
11
9
include SortHelper
12
10
helper ContextMenusHelper
13
11
14
12
def index
15
-
16
13
unless Setting . plugin_vault [ 'use_redmine_encryption' ] ||
17
- Setting . plugin_vault [ 'use_null_encryption' ]
14
+ Setting . plugin_vault [ 'use_null_encryption' ]
18
15
if not Setting . plugin_vault [ 'encryption_key' ] or Setting . plugin_vault [ 'encryption_key' ] . empty?
19
16
render_error t ( "error.key.not_set" )
20
17
return
@@ -39,8 +36,8 @@ def index
39
36
end
40
37
41
38
@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
44
41
45
42
@limit = per_page_option
46
43
@key_count = @keys . count
@@ -61,7 +58,7 @@ def index
61
58
end
62
59
63
60
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 )
65
62
render_error t ( "error.user.not_allowed" )
66
63
return
67
64
end
@@ -97,8 +94,8 @@ def all
97
94
end
98
95
99
96
@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
102
99
103
100
@limit = per_page_option
104
101
@key_count = @keys . count
@@ -131,12 +128,11 @@ def copy
131
128
132
129
def create
133
130
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 ]
136
134
@key . project = @project
137
-
138
- @key . tags = Vault ::Tag . create_from_string ( key_params [ :tags ] )
139
-
135
+
140
136
self . update_wishlist
141
137
142
138
respond_to do |format |
@@ -151,48 +147,48 @@ def create
151
147
def update
152
148
save_file if key_params [ :file ]
153
149
respond_to do |format |
154
-
155
150
self . update_wishlist
151
+ @key . safe_attributes = key_params . except ( :tags )
156
152
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 ]
159
155
format . html { redirect_to project_keys_path ( @project ) , notice : t ( 'notice.key.update.success' ) }
160
156
else
161
- format . html { render action : 'edit' }
157
+ format . html { render action : 'edit' }
162
158
end
163
159
end
164
160
end
165
161
166
162
def update_wishlist
167
163
if User . current . allowed_to? ( :manage_whitelist_keys , @key . project )
168
164
if params [ :whitelist ] . blank?
169
- @key . whitelist = ""
165
+ @key . whitelist = ""
170
166
else
171
- @key . whitelist = params [ :whitelist ] . join ( "," )
167
+ @key . whitelist = params [ :whitelist ] . join ( "," )
172
168
end
173
169
end
174
170
end
175
171
176
172
def edit
177
- if !@key . whitelisted? ( User , @project )
173
+ if !@key . whitelisted? ( User . current , @project )
178
174
render_error t ( "error.key.not_whitelisted" )
179
175
return
180
176
else
181
177
@key . decrypt!
182
178
respond_to do |format |
183
- format . html { render action : 'edit' }
179
+ format . html { render action : 'edit' }
184
180
end
185
181
end
186
182
end
187
183
188
184
def show
189
- if !@key . whitelisted? ( User , @project )
185
+ if !@key . whitelisted? ( User . current , @project )
190
186
render_error t ( "error.key.not_whitelisted" )
191
187
return
192
188
else
193
189
@key . decrypt!
194
190
respond_to do |format |
195
- format . html { render action : 'show' }
191
+ format . html { render action : 'show' }
196
192
end
197
193
end
198
194
end
@@ -204,23 +200,23 @@ def destroy
204
200
end
205
201
206
202
def context_menu
207
- #FIXME
203
+ # FIXME
208
204
@keys . map ( &:decrypt! )
209
205
render layout : false
210
206
end
211
207
212
208
private
213
209
214
210
def find_key
215
- @key = Vault ::Key . find ( params [ :id ] )
211
+ @key = Vault ::Key . find ( params [ :id ] )
216
212
unless @key . project_id == @project . id
217
213
redirect_to project_keys_path ( @project ) , notice : t ( 'alert.key.not_found' )
218
214
end
219
215
end
220
216
221
217
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 }
224
220
redirect_to project_keys_path ( @project ) , notice : t ( 'alert.key.not_found' )
225
221
end
226
222
end
@@ -239,7 +235,7 @@ def save_file
239
235
params [ 'vault_key' ] [ 'file' ] = name
240
236
end
241
237
242
- def projects_for_jump_box ( user = User . current )
238
+ def projects_for_jump_box ( user = User . current )
243
239
if user . logged?
244
240
user . projects . active . select ( :id , :name , :identifier , :lft , :rgt ) . to_a
245
241
else
0 commit comments