From 04fa9bb72b46226ae67ec29bc502b9dde4ce626e Mon Sep 17 00:00:00 2001 From: Taico Aerts Date: Thu, 19 Jan 2023 22:44:20 +0100 Subject: [PATCH 1/9] Add helper for checking whether part of codidact --- app/controllers/application_controller.rb | 5 +++++ app/helpers/codidact_helper.rb | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 app/helpers/codidact_helper.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f323a6caa..9413c7220 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -369,4 +369,9 @@ def authenticate_user!(_fav = nil, **_opts) end end end + + # Whether this host is on the codidact network + def codidact? + helpers.codidact? + end end diff --git a/app/helpers/codidact_helper.rb b/app/helpers/codidact_helper.rb new file mode 100644 index 000000000..caef5116e --- /dev/null +++ b/app/helpers/codidact_helper.rb @@ -0,0 +1,11 @@ +# Provides helper methods to determine whether this site is part of the codidact network +module CodidactHelper + # Whether this server is part of the codidact network. + def codidact? + Rails.cache.fetch 'is_codidact' do + Rails.env.development? || + RequestContext.community.host.include?('.codidact.com') || + RequestContext.community.host.include?('.codidact.org') + end + end +end \ No newline at end of file From 670937f4ccef0a244c21aa6da633eb2a2215afc9 Mon Sep 17 00:00:00 2001 From: Taico Aerts Date: Thu, 19 Jan 2023 22:45:25 +0100 Subject: [PATCH 2/9] Make devise pages less codidact dependent --- .../devise/mailer/confirmation_instructions.html.erb | 6 +++++- app/views/devise/registrations/new.html.erb | 10 ++++++---- app/views/layouts/devise_mailer.html.erb | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/views/devise/mailer/confirmation_instructions.html.erb b/app/views/devise/mailer/confirmation_instructions.html.erb index 84617ad42..be518f93f 100644 --- a/app/views/devise/mailer/confirmation_instructions.html.erb +++ b/app/views/devise/mailer/confirmation_instructions.html.erb @@ -1,4 +1,8 @@ -

Welcome to Codidact, <%= @resource.username %>! We're glad you're here.

+<% if codidact? %> +

Welcome to Codidact, <%= @resource.username %>! We're glad you're here.

+<% else %> +

Welcome, <%= @resource.username %>! We're glad you're here.

+<% end %>

Please confirm your registration by clicking below (or copy and paste the URL into your browser).

diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index 8fc1a62a7..5830af0d9 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -7,10 +7,12 @@ <% end %> -
- If you have an account on another Codidact site, - don't create a new account here - <%= link_to 'sign in', new_user_session_path %> with your existing details instead. -
+<% if codidact? %> +
+ If you have an account on another Codidact site, + don't create a new account here - <%= link_to 'sign in', new_user_session_path %> with your existing details instead. +
+<% end %> <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= render "devise/shared/error_messages", resource: resource %> diff --git a/app/views/layouts/devise_mailer.html.erb b/app/views/layouts/devise_mailer.html.erb index b3a260e52..f8dc724c8 100644 --- a/app/views/layouts/devise_mailer.html.erb +++ b/app/views/layouts/devise_mailer.html.erb @@ -10,8 +10,8 @@
<%= link_to root_url, class: 'header--site-name' do %> - <%= image_tag asset_path('codidact.png', host: 'meta.codidact.com', protocol: 'https'), height: 40, width: 167, - alt: 'Codidact logo' %> + <%= image_tag "https://#{RequestContext.community.host}#{SiteSetting['SiteLogoPath']}", height: 40, width: 167, + alt: "#{SiteSetting['SiteName']} logo" %> <% end %>
From c192ac85931298feb9bee027d59a0ee96fda56f4 Mon Sep 17 00:00:00 2001 From: Taico Aerts Date: Thu, 19 Jan 2023 22:45:56 +0100 Subject: [PATCH 3/9] Make error pages codidact independent --- app/views/errors/internal_server_error.html.erb | 12 +++++++----- app/views/errors/unprocessable_entity.html.erb | 15 ++++++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/views/errors/internal_server_error.html.erb b/app/views/errors/internal_server_error.html.erb index b98194a30..1ff668ff2 100644 --- a/app/views/errors/internal_server_error.html.erb +++ b/app/views/errors/internal_server_error.html.erb @@ -12,11 +12,13 @@

This error has been logged. We even look at them sometimes.

-

- You can also report this - on Meta - to help us keep track of what's going wrong — quote error ID <%= @log.uuid %>. -

+<% if codidact? %> +

+ You can also report this + on Meta + to help us keep track of what's going wrong — quote error ID <%= @log.uuid %>. +

+<% end %>

<%= link_to 'Go back', :back, class: 'button is-outlined' %> diff --git a/app/views/errors/unprocessable_entity.html.erb b/app/views/errors/unprocessable_entity.html.erb index ab5ed403e..8230ceae3 100644 --- a/app/views/errors/unprocessable_entity.html.erb +++ b/app/views/errors/unprocessable_entity.html.erb @@ -5,11 +5,16 @@

Your request couldn't be processed.

-

- Our server's sulking today. Log out and back in, and if this keeps happening, let us know - on Meta. -

- +<% if codidact? %> +

+ Our server's sulking today. Log out and back in, and if this keeps happening, let us know + on Meta. +

+<% else %> +

+ Our server's sulking today. Log out and back in, and if this keeps happening, let us know. +

+<% end %>

<%= link_to 'Go back', :back, class: 'button is-outlined' %> From 37c0a31efe741619761ae5fe63b3703ea1d8b571 Mon Sep 17 00:00:00 2001 From: Taico Aerts Date: Thu, 19 Jan 2023 23:03:21 +0100 Subject: [PATCH 4/9] Decouple footer --- app/views/layouts/_footer.html.erb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb index b00c2c03f..77611978c 100644 --- a/app/views/layouts/_footer.html.erb +++ b/app/views/layouts/_footer.html.erb @@ -7,19 +7,23 @@

  • <%= link_to 'Terms of Service', '/policy/tos' %>
  • <%= link_to 'Privacy Policy', '/policy/privacy-policy' %>
  • <%= link_to 'Code of Conduct', '/policy/code-of-conduct' %>
  • -
  • <%= link_to 'About us', 'https://codidact.org/' %>
  • -
  • <%= link_to 'Contact us', 'https://codidact.com/contact' %>
  • -
  • <%= link_to 'Other communities', 'https://codidact.com/' %>
  • - - -
    -

    Other Codidact Communities

    -
      - <% Rails.cache.persistent('codidact_sites').each do |site| %> -
    • <%= link_to site['name'], site['canonical_url'] %>
    • + <% if codidact? %> +
    • <%= link_to 'About us', 'https://codidact.org/' %>
    • +
    • <%= link_to 'Contact us', 'https://codidact.com/contact' %>
    • +
    • <%= link_to 'Other communities', 'https://codidact.com/' %>
    • <% end %>
    + <% if codidact? %> +
    +

    Other Codidact Communities

    +
      + <% Rails.cache.persistent('codidact_sites').each do |site| %> +
    • <%= link_to site['name'], site['canonical_url'] %>
    • + <% end %> +
    +
    + <% end %> <% commit = Rails.cache.persistent('current_commit') %>

    From fe0fc8a4d79b47969ad8d0229f407f07eb5a87a8 Mon Sep 17 00:00:00 2001 From: Taico Aerts Date: Thu, 19 Jan 2023 23:03:49 +0100 Subject: [PATCH 5/9] Decouple head --- app/views/layouts/_head.html.erb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/_head.html.erb b/app/views/layouts/_head.html.erb index c9bf20abd..a50b373c8 100644 --- a/app/views/layouts/_head.html.erb +++ b/app/views/layouts/_head.html.erb @@ -1,7 +1,10 @@ -<% desc = "#{SiteSetting['SiteName']} on Codidact - open, community-run Q&A knowledge sharing" %> +<% desc = codidact? ? + "#{SiteSetting['SiteName']} on Codidact - open, community-run Q&A knowledge sharing" : + "#{SiteSetting['SiteName']} - Q&A knowledge sharing" +%> <% page_title = (Rails.env.development? ? '[DEV] ' : '') + @@ -14,7 +17,7 @@ <% icon_path = SiteSetting['IconPath'] %> + title="<%= "#{codidact? ? 'Codidact ' : ''}#{RequestContext.community.name}" %> search" href="<%= osd_url(format: :xml) %>" /> From bc21bd22c22c7b3a068edc9792277fbaeaeada1e Mon Sep 17 00:00:00 2001 From: Taico Aerts Date: Thu, 19 Jan 2023 23:04:03 +0100 Subject: [PATCH 6/9] Decouple sidebar --- app/views/layouts/_sidebar.html.erb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/views/layouts/_sidebar.html.erb b/app/views/layouts/_sidebar.html.erb index 33a713a42..78c6a724c 100644 --- a/app/views/layouts/_sidebar.html.erb +++ b/app/views/layouts/_sidebar.html.erb @@ -106,14 +106,20 @@

    - + <% if codidact? %> + + <% else %> + + <% end %>
    <% chat = SiteSetting['ChatLink'] %> -

    - This community is part of the Codidact network. - We have other communities too — take a look! -

    + <% if codidact? %> +

    + This community is part of the Codidact network. + We have other communities too — take a look! +

    + <% end %> <% if chat.present? %>

    You can also <%= link_to 'join us in chat', chat %>! From 384b3574852445371d70739a2ffbd15ed15b8dcd Mon Sep 17 00:00:00 2001 From: Taico Aerts Date: Thu, 19 Jan 2023 23:21:45 +0100 Subject: [PATCH 7/9] Decouple mailer view partially --- app/views/layouts/mailer.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb index bdf01890b..2ed1303ef 100644 --- a/app/views/layouts/mailer.html.erb +++ b/app/views/layouts/mailer.html.erb @@ -10,8 +10,8 @@

    <%= link_to root_url, class: 'header--site-name' do %> - <%= image_tag asset_path('codidact.png', host: 'meta.codidact.com', protocol: 'https'), height: 40, width: 167, - alt: 'Codidact logo' %> + <%= image_tag "https://#{RequestContext.community.host}#{SiteSetting['SiteLogoPath']}", height: 40, width: 167, + alt: "#{SiteSetting['SiteName']} logo" %> <% end %>
    From 13c4938eba837d3ad77e7d7849c754cf3357616a Mon Sep 17 00:00:00 2001 From: Taico Aerts Date: Thu, 19 Jan 2023 23:24:15 +0100 Subject: [PATCH 8/9] Ensure url ends with, rather than just contains Thanks github code scanning bot :) --- app/helpers/codidact_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/codidact_helper.rb b/app/helpers/codidact_helper.rb index caef5116e..8821bd67e 100644 --- a/app/helpers/codidact_helper.rb +++ b/app/helpers/codidact_helper.rb @@ -4,8 +4,8 @@ module CodidactHelper def codidact? Rails.cache.fetch 'is_codidact' do Rails.env.development? || - RequestContext.community.host.include?('.codidact.com') || - RequestContext.community.host.include?('.codidact.org') + RequestContext.community.host.end_with?('.codidact.com') || + RequestContext.community.host.end_with?('.codidact.org') end end end \ No newline at end of file From 751ea047bc3dc0587392b08fc6c1e32f8e20f4fb Mon Sep 17 00:00:00 2001 From: Taico Aerts Date: Thu, 19 Jan 2023 23:26:09 +0100 Subject: [PATCH 9/9] Fix rubocop error --- app/helpers/codidact_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/codidact_helper.rb b/app/helpers/codidact_helper.rb index 8821bd67e..71e2567a7 100644 --- a/app/helpers/codidact_helper.rb +++ b/app/helpers/codidact_helper.rb @@ -8,4 +8,4 @@ def codidact? RequestContext.community.host.end_with?('.codidact.org') end end -end \ No newline at end of file +end