-
Notifications
You must be signed in to change notification settings - Fork 233
/
environment_variable_groups_controller.rb
89 lines (74 loc) · 2.06 KB
/
environment_variable_groups_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# frozen_string_literal: true
class EnvironmentVariableGroupsController < ApplicationController
before_action :authorize_user!, except: [:index, :show, :preview]
before_action :group, only: [:show]
def index
@groups = EnvironmentVariableGroup.all.includes(:environment_variables)
respond_to do |format|
format.html
format.json do
render_as_json :environment_variable_groups, @groups, nil, allowed_includes: [
:environment_variables,
]
end
end
end
def new
render 'form'
end
def create
group.attributes = attributes
group.save!
redirect_to action: :index
end
def show
render 'form'
end
def update
group.update_attributes!(attributes)
redirect_to action: :index
end
def destroy
group.destroy!
redirect_to action: :index
end
def preview
deploy_groups =
if deploy_group = params[:deploy_group].presence
[DeployGroup.find_by_permalink!(deploy_group)]
else
DeployGroup.all
end
if group_id = params[:group_id]
@group = EnvironmentVariableGroup.find(group_id)
@project = Project.new(environment_variable_groups: [@group])
else
@project = Project.find(params[:project_id])
end
options = {project_specific: params[:project_specific]}
options.merge!(params[:preview] ? {preview: true, resolve_secrets: true} : {resolve_secrets: false})
@groups = SamsonEnv.env_groups(Deploy.new(project: @project), deploy_groups, **options)
respond_to do |format|
format.html
format.json { render json: {groups: @groups || []} }
end
end
private
def group
@group ||= if ['new', 'create'].include?(action_name)
EnvironmentVariableGroup.new
else
EnvironmentVariableGroup.find(params[:id])
end
end
def attributes
params.require(:environment_variable_group).permit(
:name,
:comment,
AcceptsEnvironmentVariables::ASSIGNABLE_ATTRIBUTES
)
end
def authorize_user!
unauthorized! unless can? :write, :environment_variable_groups, group
end
end