Skip to content

fix(front): remove redundant checks from add people button visibility check #431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions front/config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,11 @@ config :front,

config :front, :on_prem?, on_prem?

if on_prem? do
config :front,
feature_provider:
{FeatureProvider.YamlProvider,
[yaml_path: System.get_env("FEATURE_YAML_PATH"), agent_name: :feature_provider_agent]}

config :front, JobPage.Api.Loghub, timeout: :timer.minutes(2)
else
edition = System.get_env("EDITION", "") |> String.trim() |> String.downcase()
is_saas? = !(on_prem? or edition in ["ce", "ee"])

if is_saas? do
config :front,
feature_provider:
{Front.FeatureHubProvider,
Expand All @@ -147,6 +144,13 @@ else
{FeatureProvider.CachexCache,
name: :feature_provider_cache, ttl_ms: :timer.minutes(10)}
]}
else
config :front,
feature_provider:
{FeatureProvider.YamlProvider,
[yaml_path: System.get_env("FEATURE_YAML_PATH"), agent_name: :feature_provider_agent]}

config :front, JobPage.Api.Loghub, timeout: :timer.minutes(2)
end

if System.get_env("AMQP_URL") != nil do
Expand Down Expand Up @@ -190,6 +194,4 @@ config :front,
:single_tenant,
System.get_env("SINGLE_TENANT") == "true"

config :front,
:edition,
System.get_env("EDITION", "") |> String.trim() |> String.downcase()
config :front, :edition, edition
2 changes: 0 additions & 2 deletions front/helm/templates/job-page.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ spec:
{{- end }}
- name: METRICS_SERVICE
value: "front"
- name: ON_PREM
value: "true"
- name: FEATURE_YAML_PATH
value: {{ .Values.featureFlags.mountPath | quote }}
- name: GETTING_STARTED_YAML_PATH
Expand Down
2 changes: 0 additions & 2 deletions front/helm/templates/project-page.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ spec:
{{- end }}
- name: METRICS_SERVICE
value: "front"
- name: ON_PREM
value: "true"
- name: START_TELEMETRY
value: {{ .Values.global.telemetry.enabled | quote }}
- name: TELEMETRY_CRON
Expand Down
2 changes: 0 additions & 2 deletions front/helm/templates/ui-cache-reactor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ spec:
- name: METRICS_NAMESPACE
value: {{ .Values.global.statsd.metricsNamespace }}
{{- end }}
- name: ON_PREM
value: "true"
- name: FEATURE_YAML_PATH
value: {{ .Values.featureFlags.mountPath | quote }}
- name: GETTING_STARTED_YAML_PATH
Expand Down
8 changes: 8 additions & 0 deletions front/lib/front.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@ defmodule Front do
def os? do
ee?() || ce?()
end

@doc """
Check if we're running on saas or not
"""
@spec saas?() :: boolean()
def saas? do
!(on_prem?() or os?())
end
end
14 changes: 7 additions & 7 deletions front/lib/front/clients/billing.ex
Original file line number Diff line number Diff line change
Expand Up @@ -314,26 +314,26 @@ defmodule Front.Clients.Billing do

defp call_grpc(error = {:error, err}, _, _, _, _, _) do
Logger.error("""
Unexpected error when connecting to Velocity: #{inspect(err)}
Unexpected error when connecting to Billing: #{inspect(err)}
""")

error
end

defp call_grpc({:ok, channel}, module, function_name, request, metadata, timeout) do
if Front.on_prem?() do
{:error, "Billing service is not running on on-prem instance"}
else
if Front.saas?() do
apply(module, function_name, [channel, request, [metadata: metadata, timeout: timeout]])
else
{:error, "Billing service is running only on saas instance"}
end
end

defp channel do
if Front.on_prem?() do
{:error, "Billing service is not running on on-prem instance"}
else
if Front.saas?() do
Application.fetch_env!(:front, :billing_api_grpc_endpoint)
|> GRPC.Stub.connect()
else
{:error, "Billing service is running only on saas instance"}
end
end

Expand Down
2 changes: 1 addition & 1 deletion front/lib/front/layout/cache_invalidator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ defmodule Front.Layout.CacheInvalidator do
end

def invalidate_billing(org_id) do
if not Front.on_prem?() do
if Front.saas?() do
Front.Clients.Billing.invalidate_cache(:list_spendings, %{org_id: org_id})
Front.Clients.Billing.invalidate_cache(:current_spending, %{org_id: org_id})
Front.Clients.Billing.invalidate_cache(:credits_usage, %{org_id: org_id})
Expand Down
6 changes: 3 additions & 3 deletions front/lib/front/models/organization_onboarding.ex
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ defmodule Front.Models.OrganizationOnboarding do

@spec validate_billing(model :: t()) :: :ok | {:error, String.t()}
defp validate_billing(model) do
if Front.on_prem?() do
:ok
else
if Front.saas?() do
BillingClient.can_setup_organization(%{
owner_id: model.user_id
})
Expand All @@ -136,6 +134,8 @@ defmodule Front.Models.OrganizationOnboarding do
{:ok, %{allowed: false, errors: messages}} -> {:error, Enum.join(messages, ", ")}
{:error, _} -> {:error, "Account check failed"}
end
else
:ok
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ defmodule FrontWeb.ProjectOnboardingController do
) do
project_onboarding_path(conn, :onboarding_index, project.name, [""])
else
# TODO: check with Amir
if Front.on_prem?() do
if Models.Project.file_exists?(project.id, project.initial_pipeline_file) do
project_onboarding_path(conn, :existing_configuration, project.name)
Expand Down
44 changes: 22 additions & 22 deletions front/lib/front_web/templates/account/show.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -27,48 +27,48 @@
<%= case {@user.github_scope, @user.github_login} do %>
<% {:NONE, nil} -> %>
<span class="red">Not Connected</span>
<%= unless Front.on_prem?() do %>
<div>
<%= link "Grant public access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :public]), method: :post %>
<%= link "Grant private access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :private]), method: :post %>
</div>
<%= if Front.saas?() do %>
<div>
<%= link "Grant public access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :public]), method: :post %>
<%= link "Grant private access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :private]), method: :post %>
</div>
<% else %>
<div>
<%= link "Connect…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :email]), method: :post %>
</div>
<div>
<%= link "Connect…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :email]), method: :post %>
</div>
<% end %>
<% {:NONE, _} -> %>
<span class="red">Not Connected</span>
Β·
<span><a href="https://github.com/<%= @user.github_login %>" target="_blank">@<%= @user.github_login %></a></span>
<%= unless Front.on_prem?() do %>
<div>
<%= link "Grant public access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :public]), method: :post %>
<%= link "Grant private access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :private]), method: :post %>
</div>
<%= if Front.saas?() do %>
<div>
<%= link "Grant public access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :public]), method: :post %>
<%= link "Grant private access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :private]), method: :post %>
</div>
<% end %>
<% {:EMAIL, _} -> %>
<span class="green">Connected</span>
Β·
<span class="gray">email only</span>
Β·
<span><a href="https://github.com/<%= @user.github_login %>" target="_blank">@<%= @user.github_login %></a></span>
<%= unless Front.on_prem?() do %>
<div>
<%= link "Grant public access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :public]), method: :post %>
<%= link "Grant private access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :private]), method: :post %>
</div>
<%= if Front.saas?() do %>
<div>
<%= link "Grant public access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :public]), method: :post %>
<%= link "Grant private access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :private]), method: :post %>
</div>
<% end %>
<% {:PUBLIC, _} -> %>
<span class="green">Connected</span>
Β·
<span class="gray">public repositories</span>
Β·
<span><a href="https://github.com/<%= @user.github_login %>" target="_blank">@<%= @user.github_login %></a></span>
<%= unless Front.on_prem?() do %>
<div>
<%= link "Grant private access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :private]), method: :post %>
</div>
<%= if Front.saas?() do %>
<div>
<%= link "Grant private access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :private]), method: :post %>
</div>
<% end %>
<% {:PRIVATE, _} -> %>
<span class="green">Connected</span>
Expand Down
4 changes: 2 additions & 2 deletions front/lib/front_web/templates/error/404.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<a href="https://me.<%= Application.fetch_env!(:front, :domain) %>/" class="db">
<img src="<%= assets_path() %>/images/semaphore-logo-full-white.svg" alt="Semaphore Logo">
</a>
<%= if not Front.on_prem?() do %>
<%= if Front.saas?() do %>
<div class="flex-ns items-center">
<div class="f5 fw5 pr2 mv3 mv0-m flex justify-center">
<a href="https://<%= Application.fetch_env!(:front, :domain) %>/product" class="link white-90 hover-white ph2">Product</a>
Expand Down Expand Up @@ -72,7 +72,7 @@
<%= if anonymous?(@conn) do %>
<p class="f4 black-80 mb3=0">Perhaps you need to <a href="<%= login_url(@conn) %>" class="link black-50 hover-black-80">log in β†’</a></p>
<% else %>
<%= if not Front.on_prem?() do %>
<%= if Front.saas?() do %>
<%= if Enum.all?([:user, :project], fn m -> Enum.member?(Map.keys(@conn.assigns), m) end) do %>
<%= if @conn.assigns.user.gitlab_scope == :NONE &&
@conn.assigns.project.integration_type == :GITLAB do %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="flex items-center flex-shrink-0">
<p class="f6 mb0">Blazing-fast build and deploy!</p>
<a href="<%= login_url(@conn) %>" class="btn btn-secondary btn-small ml3">Log in</a>
<%= if not Front.on_prem?() do %>
<%= if Front.saas?() do %>
<a href="<%= signup_url(@conn) %>" class="btn btn-secondary btn-small ml3">Sign up</a>
<% end %>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<%= link "Okta Integration", to: organization_okta_path(@conn, :show), class: "link db pv1 ph3 br3 dark-gray hover-bg-lightest-gray" %>
<% end %>
<% end %>
<%= if not Front.on_prem?() do %>
<%= if Front.saas?() do %>
<%= if @conn.request_path =~ organization_contacts_path(@conn, :show) do %>
<%= link "Contacts", to: organization_contacts_path(@conn, :show), class: "link db pv1 ph3 br3 bg-green white" %>
<% else %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<%= if show_people_management_buttons?(@conn, @org_scope?, @permissions) do %>
<div>
<%= if @org_scope? do %>
<div id="add-people" data-config="<%= Poison.encode!(add_people_config(@conn)) %>"></div>
<%= if !Front.on_prem?() do %>
<div id="add-people" data-config="<%= Poison.encode!(add_people_config(@conn)) %>"></div>
<% end %>
<% else %>
<div class="flex-m">
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
<div class="b">People</div>
</div>
</div>
<%= if !@org_scope? || !Front.on_prem?() || Front.ce_roles?() do %>
<%= render "members/_add_people_button.html", conn: @conn, org_scope?: @org_scope?, permissions: @permissions %>
<% end %>
<%= render "members/_add_people_button.html", conn: @conn, org_scope?: @org_scope?, permissions: @permissions %>
</div>

<div id="members">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<%= render "members/members_list.html", org_id: @org_id, groups: @groups, members: @members, roles: @roles, org_scope?: @org_scope?, conn: @conn, permissions: @permissions %>
<%= render "_pagination.html", pagination: @pagination%>

<%= if not Front.on_prem?() do %>
<%= if Front.saas?() do %>
<div id="invitees">
<%= @invitations |> Enum.map(fn (invitee) -> %>
<%= render "members/_invitee.html", invitee: invitee, conn: @conn %>
Expand Down
Loading