[feat] allow organizations to add custom logo (de-hardcodes Redeira custom logo)

This commit is contained in:
Marc Anguera Insa
2023-02-13 22:14:55 +01:00
parent 4208e1a23a
commit a70ef9b555
12 changed files with 22 additions and 91 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

+1 -1
View File
@@ -52,6 +52,6 @@ class OrganizationsController < ApplicationController
def organization_params
params[:organization].permit(*%w[name theme email phone web
public_opening_times description address
neighborhood city domain])
neighborhood city domain logo])
end
end
+11
View File
@@ -24,6 +24,17 @@ module ApplicationHelper
"https://www.gravatar.com/avatar/#{gravatar_id}.png?#{gravatar_options.to_param}"
end
def organization_logo
org = @organization || @current_organization
return unless org && org.logo.attached?
return if "#{controller_name}##{action_name}".in? %w(organizations#index pages#show)
content_tag(:div, class: "row") do
image_tag(org.logo.variant(resize: "x200^"), class: 'img-responsive center-block')
end
end
def mdash
raw "&mdash;"
end
-17
View File
@@ -1,17 +0,0 @@
module BrandLogoHelper
def render_brand_logo
return unless should_render_logo?
render 'application/brand_logo'
end
private
def should_render_logo?
return false unless current_user
current_organization&.id == branded_organization_id
end
def branded_organization_id
Rails.application.config.branded_organization_id
end
end
+2
View File
@@ -10,6 +10,8 @@ class Organization < ApplicationRecord
}
}
has_one_attached :logo
has_many :members, dependent: :destroy
has_many :users, -> { order "members.created_at DESC" }, through: :members
has_many :all_accounts, class_name: "Account", inverse_of: :organization, dependent: :destroy
+1
View File
@@ -20,6 +20,7 @@ class User < ApplicationRecord
attr_accessor :from_signup
has_one_attached :avatar
has_many :members, dependent: :destroy
has_many :organizations, through: :members
has_many :accounts, through: :members
@@ -1,3 +0,0 @@
<div class="container" style="margin-bottom: 30px">
<%= image_tag("redeira.png", class: 'organization-brand-logo img-responsive center-block') %>
</div>
+1 -2
View File
@@ -18,14 +18,13 @@
<div class="container content">
<%= render 'layouts/messages' unless devise_controller? %>
<%= yield %>
<%= organization_logo %>
</div>
<div class="modal fade" id="modal">
<div class="modal-dialog">
<div class="modal-content"></div>
</div>
</div>
<%= render_brand_logo %>
<%= render 'application/footer' %>
</body>
</html>
+1
View File
@@ -9,5 +9,6 @@
<%= f.input :address %>
<%= f.input :neighborhood %>
<%= f.input :city %>
<%= f.input :logo %>
<%= f.button :submit %>
<% end %>
@@ -15,9 +15,12 @@
data: { confirm: t('users.user_rows.sure_delete', organization_name: org.name) },
class: 'btn btn-danger' %>
<% elsif petition && !current_user.was_member?(petition) %>
<%= petition.status %>
<span class="badge"><%= petition.status %></span>
<% else %>
<%= link_to t('petitions.apply'), petitions_path(user_id: current_user.id, organization_id: org.id, status: 'pending'), method: :post %>
<%= link_to t('petitions.apply'),
petitions_path(user_id: current_user.id, organization_id: org.id, status: 'pending'),
method: :post,
class: 'btn btn-default' %>
<% end %>
<% end %>
</td>
@@ -1,7 +0,0 @@
DEFAULT_BRANDED_ORG_ID = 246
Rails.application.config.branded_organization_id = nil
unless Rails.env.test?
Rails.application.config.branded_organization_id = (Redis.current.get('branded_organization_id') || DEFAULT_BRANDED_ORG_ID).to_i
end
-59
View File
@@ -1,59 +0,0 @@
RSpec.feature 'sign in' do
let(:user) do
user = Fabricate(
:user,
email: 'user@timeoverflow.org',
password: 'papapa22',
terms_accepted_at: 1.day.from_now
)
user.add_to_organization(organization)
user
end
let(:organization) { Fabricate(:organization) }
context 'with a branded org id' do
before do
allow(Rails.application.config).to receive(:branded_organization_id).and_return(organization.id)
sign_in_with(user.email, user.password)
end
it 'renders the logo' do
expect(page).to have_css('.organization-brand-logo')
end
end
context 'without a branded org id' do
before do
allow(Rails.application.config).to receive(:branded_organization_id).and_return(1234)
sign_in_with(user.email, user.password)
end
it 'does not render the logo' do
expect(page).to have_no_css('.organization-brand-logo')
end
end
end
RSpec.feature 'sign out' do
let!(:user) do
Fabricate(
:user,
email: 'user@timeoverflow.org',
password: 'papapa22',
terms_accepted_at: 1.day.from_now
)
end
context 'without a user' do
it 'does not render the logo' do
sign_in_with(user.email, user.password)
click_link user.email
click_link I18n.t('application.navbar.sign_out')
expect(page).to have_no_css('.organization-brand-logo')
end
end
end