Skip to content
Open
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
5 changes: 5 additions & 0 deletions app/models/custom_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CustomVariable < ApplicationRecord
"past_calendar_range" => :text,
"academic_calendar_range" => :text,
"quadrennial_period" => :text,
"instance_name" => :text,
}

validates :variable, presence: true
Expand Down Expand Up @@ -115,6 +116,10 @@ def self.quadrennial_period
config.blank? ? "Not defined" : config.value
end

def self.instance_name
config = CustomVariable.find_by_variable(:instance_name)
config.blank? ? nil : config.value
end

def to_label
self.variable.to_s
Expand Down
5 changes: 5 additions & 0 deletions app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
html: { id: "login_form" }
) do |f| %>
<%= flash[:name] %>
<% if CustomVariable.instance_name %>
<div style="margin-bottom: 10px;">
Login de acesso para <%= CustomVariable.instance_name %>
</div>
<% end %>

<div id="login_input">
<%= f.label :email, 'Email ou CPF' %>
Expand Down
15 changes: 11 additions & 4 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@
<% end %>
</div>
<div id="sub" style="display: flex-column;">
<div>
<div style="text-align: right;">
Versão <%= APP_VERSION %> | <%= link_to 'Créditos', credits_show_path %>
</div>
<div id="role_selector" style="float: right">
<%= role_selector(current_user) %>
</div>
<div style="float: right; text-align: right;">
<% if CustomVariable.instance_name %>
<div>
<%= CustomVariable.instance_name %>
</div>
<% end %>
<div id="role_selector">
<%= role_selector(current_user) %>
</div>
</div>
</div>
</div>
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20250903205743_create_instance_name_variable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateInstanceNameVariable < ActiveRecord::Migration[7.0]
def up
CustomVariable.where(
variable: "instance_name"
).first || CustomVariable.create(
description: "Nome do programa",
variable: "instance_name",
value: nil
)
end
end
17 changes: 17 additions & 0 deletions spec/models/custom_variable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,22 @@
expect(CustomVariable.notification_footer).to eq("bla")
end
end

context "instance_name" do
it "should return nil when there is no variable defined" do
config = CustomVariable.find_by_variable(:instance_name)
config.delete unless config.nil?

expect(CustomVariable.instance_name).to eq(nil)
end

it "should return 'Computacao' when it is defined to Computacao" do
config = CustomVariable.find_by_variable(:instance_name)
config.delete unless config.nil?
@destroy_later << CustomVariable.create(variable: :instance_name, value: "Computacao")

expect(CustomVariable.instance_name).to eq("Computacao")
end
end
end
end
Loading