Skip to content

Commit 2632e24

Browse files
skipihamir-suspect
andauthored
fix(front): remove redundant checks from add people button visibility check (#431)
## 📝 Description [_add_people_button](https://github.com/semaphoreio/semaphore/blob/d9a95d1890e5551a67c8071340b065c8bc61d213/front/lib/front_web/templates/people/members/_add_people_button.html.eex#L3) partial already performs required checks. We only need to check if we're on the `on_prem` environment. Introduces `github_user_provider`, `gitlab_user_provider` and `bitbucket_user_provider` feature flags so OS installations can enable user authentication integration with git providers. Introduces `user_repos_access` feature flag for specific setups that need to restrict users from connecting their git provider account to semaphore account. ## ✅ Checklist - [x] I have tested this change - [ ] This change requires documentation update --------- Co-authored-by: Amir Hasanbasic <[email protected]> Co-authored-by: Amir Hasanbasic <[email protected]>
1 parent eef3e21 commit 2632e24

38 files changed

+213
-193
lines changed

front/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ CONTAINER_ENV_VARS = \
5252

5353

5454
CONTAINER_CE_ENV_VARS =\
55-
-e CE_ROLES=true \
55+
-e EDITION=ce \
5656
-e SEED_CLOUD_MACHINES=false \
5757
-e SEED_SELF_HOSTED_AGENTS=true \
5858
-e SEED_CE_FEATURES=true \

front/config/runtime.exs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ config :front,
5757
cookie_name: System.get_env("COOKIE_NAME"),
5858
use_rbac_api: if(System.get_env("USE_RBAC_API") == "true", do: true, else: false)
5959

60-
on_prem? = if(System.get_env("ON_PREM") == "true", do: true, else: false)
61-
6260
# Internal API endpoints - always read from environment variables for all environments
6361
# Test environment will need these env vars set, or use stubs in test setup
6462
config :front,
@@ -131,16 +129,10 @@ config :front,
131129
zendesk_snippet_id: System.get_env("ZENDESK_SNIPPET_ID"),
132130
google_gtag: System.get_env("GOOGLE_GTAG")
133131

134-
config :front, :on_prem?, on_prem?
132+
edition = System.get_env("EDITION", "") |> String.trim() |> String.downcase()
133+
is_saas? = !(edition in ["ce", "ee"])
135134

136-
if on_prem? do
137-
config :front,
138-
feature_provider:
139-
{FeatureProvider.YamlProvider,
140-
[yaml_path: System.get_env("FEATURE_YAML_PATH"), agent_name: :feature_provider_agent]}
141-
142-
config :front, JobPage.Api.Loghub, timeout: :timer.minutes(2)
143-
else
135+
if is_saas? do
144136
config :front,
145137
feature_provider:
146138
{Front.FeatureHubProvider,
@@ -149,6 +141,13 @@ else
149141
{FeatureProvider.CachexCache,
150142
name: :feature_provider_cache, ttl_ms: :timer.minutes(10)}
151143
]}
144+
else
145+
config :front,
146+
feature_provider:
147+
{FeatureProvider.YamlProvider,
148+
[yaml_path: System.get_env("FEATURE_YAML_PATH"), agent_name: :feature_provider_agent]}
149+
150+
config :front, JobPage.Api.Loghub, timeout: :timer.minutes(2)
152151
end
153152

154153
if System.get_env("AMQP_URL") != nil do
@@ -166,8 +165,6 @@ end
166165

167166
config :front, :audit_logging, System.get_env("AUDIT_LOGGING") == "true"
168167

169-
config :front, :ce_roles, System.get_env("CE_ROLES") == "true"
170-
171168
config :front,
172169
:hide_promotions,
173170
System.get_env("HIDE_PROMOTIONS") == "true"
@@ -180,18 +177,8 @@ config :front,
180177
:new_project_onboarding_workflow_templates_path,
181178
System.fetch_env!("WORKFLOW_TEMPLATES_YAMLS_PATH") <> "_new"
182179

183-
config :front,
184-
:hide_bitbucket_me_page,
185-
System.get_env("HIDE_BITBUCKET_ME_PAGE") == "true"
186-
187-
config :front,
188-
:hide_gitlab_me_page,
189-
System.get_env("HIDE_GITLAB_ME_PAGE") == "true"
190-
191180
config :front,
192181
:single_tenant,
193182
System.get_env("SINGLE_TENANT") == "true"
194183

195-
config :front,
196-
:edition,
197-
System.get_env("EDITION", "") |> String.trim() |> String.downcase()
184+
config :front, :edition, edition

front/helm/templates/job-page.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ spec:
113113
{{- end }}
114114
- name: METRICS_SERVICE
115115
value: "front"
116-
- name: ON_PREM
117-
value: "true"
118116
- name: FEATURE_YAML_PATH
119117
value: {{ .Values.featureFlags.mountPath | quote }}
120118
- name: GETTING_STARTED_YAML_PATH
@@ -124,8 +122,6 @@ spec:
124122
{{- if eq .Values.global.edition "ce" }}
125123
- name: "SKIP_VELOCITY"
126124
value: "true"
127-
- name: "CE_ROLES"
128-
value: "true"
129125
- name: "HIDE_PROMOTIONS"
130126
value: "true"
131127
{{- end }}

front/helm/templates/project-page.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ spec:
139139
{{- end }}
140140
- name: METRICS_SERVICE
141141
value: "front"
142-
- name: ON_PREM
143-
value: "true"
144142
- name: START_TELEMETRY
145143
value: {{ .Values.global.telemetry.enabled | quote }}
146144
- name: TELEMETRY_CRON
@@ -154,8 +152,6 @@ spec:
154152
{{- if eq .Values.global.edition "ce" }}
155153
- name: "SKIP_VELOCITY"
156154
value: "true"
157-
- name: "CE_ROLES"
158-
value: "true"
159155
- name: "HIDE_PROMOTIONS"
160156
value: "true"
161157
{{- end }}

front/helm/templates/ui-cache-reactor.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ spec:
9595
- name: METRICS_NAMESPACE
9696
value: {{ .Values.global.statsd.metricsNamespace }}
9797
{{- end }}
98-
- name: ON_PREM
99-
value: "true"
10098
- name: FEATURE_YAML_PATH
10199
value: {{ .Values.featureFlags.mountPath | quote }}
102100
- name: GETTING_STARTED_YAML_PATH
@@ -106,8 +104,6 @@ spec:
106104
{{- if eq .Values.global.edition "ce" }}
107105
- name: "SKIP_VELOCITY"
108106
value: "true"
109-
- name: "CE_ROLES"
110-
value: "true"
111107
- name: "HIDE_PROMOTIONS"
112108
value: "true"
113109
{{- end }}

front/lib/front.ex

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
11
defmodule Front do
2-
@doc """
3-
Checks if application is running on-prem environment
4-
"""
5-
@spec on_prem?() :: boolean()
6-
def on_prem? do
7-
Application.get_env(:front, :on_prem?)
8-
end
9-
10-
@spec ce_roles?() :: boolean()
11-
def ce_roles? do
12-
Application.get_env(:front, :ce_roles)
13-
end
14-
152
@doc """
163
Check if it's CE edition
174
"""
@@ -35,4 +22,12 @@ defmodule Front do
3522
def os? do
3623
ee?() || ce?()
3724
end
25+
26+
@doc """
27+
Check if we're running on saas or not
28+
"""
29+
@spec saas?() :: boolean()
30+
def saas? do
31+
!os?()
32+
end
3833
end

front/lib/front/clients/billing.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,26 +314,26 @@ defmodule Front.Clients.Billing do
314314

315315
defp call_grpc(error = {:error, err}, _, _, _, _, _) do
316316
Logger.error("""
317-
Unexpected error when connecting to Velocity: #{inspect(err)}
317+
Unexpected error when connecting to Billing: #{inspect(err)}
318318
""")
319319

320320
error
321321
end
322322

323323
defp call_grpc({:ok, channel}, module, function_name, request, metadata, timeout) do
324-
if Front.on_prem?() do
325-
{:error, "Billing service is not running on on-prem instance"}
326-
else
324+
if Front.saas?() do
327325
apply(module, function_name, [channel, request, [metadata: metadata, timeout: timeout]])
326+
else
327+
{:error, "Billing service is running only on saas instance"}
328328
end
329329
end
330330

331331
defp channel do
332-
if Front.on_prem?() do
333-
{:error, "Billing service is not running on on-prem instance"}
334-
else
332+
if Front.saas?() do
335333
Application.fetch_env!(:front, :billing_api_grpc_endpoint)
336334
|> GRPC.Stub.connect()
335+
else
336+
{:error, "Billing service is running only on saas instance"}
337337
end
338338
end
339339

front/lib/front/feature_hub_provider.ex

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,29 @@ defmodule Front.FeatureHubProvider do
66
Availability,
77
Machine,
88
OrganizationFeature,
9+
Feature,
910
OrganizationMachine
1011
}
1112

1213
import Front.Utils
1314

1415
@impl FeatureProvider.Provider
15-
def provide_features(org_id, _opts \\ []) do
16+
def provide_features(org_id, opts \\ [])
17+
18+
def provide_features(nil, _opts) do
19+
%InternalApi.Feature.ListFeaturesRequest{}
20+
|> FeatureClient.list_features()
21+
|> unwrap(fn response ->
22+
features =
23+
response.features
24+
|> Enum.map(&feature_from_grpc/1)
25+
|> Enum.filter(&FeatureProvider.Feature.visible?/1)
26+
27+
ok(features)
28+
end)
29+
end
30+
31+
def provide_features(org_id, _opts) do
1632
FeatureClient.list_organization_features(%{org_id: org_id})
1733
|> unwrap(fn response ->
1834
features =
@@ -38,6 +54,21 @@ defmodule Front.FeatureHubProvider do
3854
end)
3955
end
4056

57+
defp feature_from_grpc(%Feature{
58+
availability: availability,
59+
name: name,
60+
type: type,
61+
description: description
62+
}) do
63+
%FeatureProvider.Feature{
64+
name: name,
65+
type: type,
66+
description: description,
67+
quantity: quantity_from_availability(availability),
68+
state: state_from_availability(availability)
69+
}
70+
end
71+
4172
defp feature_from_grpc(%OrganizationFeature{feature: feature, availability: availability}) do
4273
%FeatureProvider.Feature{
4374
name: feature.name,

front/lib/front/layout/cache_invalidator.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ defmodule Front.Layout.CacheInvalidator do
314314
end
315315

316316
def invalidate_billing(org_id) do
317-
if not Front.on_prem?() do
317+
if Front.saas?() do
318318
Front.Clients.Billing.invalidate_cache(:list_spendings, %{org_id: org_id})
319319
Front.Clients.Billing.invalidate_cache(:current_spending, %{org_id: org_id})
320320
Front.Clients.Billing.invalidate_cache(:credits_usage, %{org_id: org_id})

front/lib/front/models/organization_onboarding.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ defmodule Front.Models.OrganizationOnboarding do
125125

126126
@spec validate_billing(model :: t()) :: :ok | {:error, String.t()}
127127
defp validate_billing(model) do
128-
if Front.on_prem?() do
129-
:ok
130-
else
128+
if Front.saas?() do
131129
BillingClient.can_setup_organization(%{
132130
owner_id: model.user_id
133131
})
@@ -136,6 +134,8 @@ defmodule Front.Models.OrganizationOnboarding do
136134
{:ok, %{allowed: false, errors: messages}} -> {:error, Enum.join(messages, ", ")}
137135
{:error, _} -> {:error, "Account check failed"}
138136
end
137+
else
138+
:ok
139139
end
140140
end
141141

0 commit comments

Comments
 (0)