Skip to content

Commit 094acd3

Browse files
committed
pr97
1 parent 0bbcef7 commit 094acd3

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

app/controllers/keys_controller.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def index
3737
end
3838

3939
@keys = @keys.order(sort_clause) unless @keys.nil?
40-
@keys = @keys.select { |key| key.whitelisted?(User, @project) } unless @keys.nil?
40+
@keys = @keys.select { |key| key.whitelisted?(User.current, @project) } unless @keys.nil?
4141
@keys = [] if @keys.nil? # hack for decryption
4242

4343
@limit = per_page_option
@@ -95,7 +95,7 @@ def all
9595
end
9696

9797
@keys = @keys.order(sort_clause) unless @keys.nil?
98-
@keys = @keys.select { |key| key.whitelisted?(User, key.project) } unless @keys.nil?
98+
@keys = @keys.select { |key| key.whitelisted?(User.current, key.project) } unless @keys.nil?
9999
@keys = [] if @keys.nil? # hack for decryption
100100

101101
@limit = per_page_option
@@ -169,7 +169,7 @@ def update_wishlist
169169
end
170170

171171
def edit
172-
if !@key.whitelisted?(User, @project)
172+
if !@key.whitelisted?(User.current, @project)
173173
render_error t("error.key.not_whitelisted")
174174
return
175175
else
@@ -181,7 +181,7 @@ def edit
181181
end
182182

183183
def show
184-
if !@key.whitelisted?(User, @project)
184+
if !@key.whitelisted?(User.current, @project)
185185
render_error t("error.key.not_whitelisted")
186186
return
187187
else

app/controllers/tags_controller.rb

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

app/models/vault/key.rb

+13-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ module Vault
33
require 'iconv'
44

55
class Vault::Key < ActiveRecord::Base
6+
include Redmine::SafeAttributes
7+
68
belongs_to :project
79
has_and_belongs_to_many :tags, join_table: 'keys_vault_tags'
810

11+
safe_attributes 'project_id', 'name', 'body', 'login', 'type', 'file', 'url', 'comment', 'whitelist'
12+
913
def tags=(tags_string)
1014
tag_objects = Vault::Tag.create_from_string(tags_string)
1115
self.tags.clear
@@ -66,13 +70,17 @@ def self.import(file)
6670
end
6771

6872
def whitelisted?(user, project)
69-
return true if user.current.admin or !user.current.allowed_to?(:whitelist_keys, project)
70-
self.whitelist.split(",").each do |id|
71-
return true if User.in_group(id).where(:id => user.current.id).count == 1
73+
return true if user.admin || !user.allowed_to?(:whitelist_keys, project)
74+
75+
whitelist_ids = self.whitelist.split(',')
76+
return true if whitelist_ids.include?(user.id.to_s)
77+
78+
whitelist_ids.each do |id|
79+
return true if User.in_group(id).where(id: user.id).any?
7280
end
73-
return self.whitelist.split(",").include?(user.current.id.to_s)
74-
end
7581

82+
false
83+
end
7684
end
7785

7886
class Vault::KeysVaultTags < ActiveRecord::Base

app/models/vault/tag.rb

+4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
module Vault
22
class Tag < ActiveRecord::Base
3+
include Redmine::SafeAttributes
4+
35
self.table_name = 'vault_tags'
46
has_and_belongs_to_many :keys, join_table: 'keys_vault_tags'
57

8+
safe_attributes 'name', 'color'
9+
610
validates :name, presence: true, uniqueness: true
711
validates :color, presence: true
812

config/locales/ru.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ru:
1111

1212
activerecord:
1313
models:
14-
password: "Ключь"
14+
password: "Ключ"
1515
sftp: "SFTP"
1616

1717
backups:

0 commit comments

Comments
 (0)