From 7bab94da5c06b36c56a07c434f309b605e9fa151 Mon Sep 17 00:00:00 2001 From: Viktor Smari Date: Tue, 26 Nov 2019 17:46:11 +0100 Subject: [PATCH] Removes Discourse iframe + sync --- app/models/lab.rb | 15 ---------- app/models/machine.rb | 16 ---------- app/models/organization.rb | 16 ---------- app/models/project.rb | 16 ---------- app/models/user.rb | 5 ---- app/views/backstage/labs/show.html.haml | 2 -- .../backstage/labs_manager/show.html.haml | 2 -- app/views/labs/show.html.haml | 6 ---- app/views/layouts/application.html.haml | 3 -- app/views/machines/show.html.haml | 7 ----- app/views/organizations/show.html.haml | 6 ---- app/views/projects/show.html.haml | 5 ---- lib/tasks/discourse.rake | 29 ------------------- 13 files changed, 128 deletions(-) delete mode 100644 lib/tasks/discourse.rake diff --git a/app/models/lab.rb b/app/models/lab.rb index 1cc92dea..58864416 100644 --- a/app/models/lab.rb +++ b/app/models/lab.rb @@ -124,7 +124,6 @@ def excluded_slug before_save :truncate_blurb before_save :get_time_zone unless Rails.env.test? after_save :save_roles - after_save :discourse_sync_if_needed, if: Figaro.env.discourse_enabled attr_accessor :geocomplete @@ -226,14 +225,6 @@ def is_approved? return true if workflow_state == "approved" end - def async_discourse_sync - DiscourseLabWorker.perform_async(self.id) - end - - def discourse_sync - DiscourseService::Lab.new(self).sync - end - def avatar_url if avatar_uid.present? avatar.thumb('150x150#').url @@ -250,12 +241,6 @@ def avatar_url private - def discourse_sync_if_needed - if (changes.keys & ["name", "description"]).present? - async_discourse_sync - end - end - def get_time_zone if latitude_changed? or longitude_changed? begin diff --git a/app/models/machine.rb b/app/models/machine.rb index 952cef2a..545894dd 100644 --- a/app/models/machine.rb +++ b/app/models/machine.rb @@ -1,24 +1,8 @@ class Machine < Thing - after_save :discourse_sync_if_needed, if: Figaro.env.discourse_enabled - def to_param slug end - def async_discourse_sync - DiscourseMachineWorker.perform_async(self.id) - end - - def discourse_sync - DiscourseService::Machine.new(self).sync - end - private - - def discourse_sync_if_needed - if (changes.keys & ["name", "description"]).present? - async_discourse_sync - end - end end diff --git a/app/models/organization.rb b/app/models/organization.rb index 88a34014..bcd82599 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -38,8 +38,6 @@ class Organization < ActiveRecord::Base scope :approved, -> {where(workflow_state: STATE_APPROVED)} - after_save :discourse_sync_if_needed, if: Figaro.env.discourse_enabled - attr_accessor :geocomplete extend FriendlyId @@ -62,14 +60,6 @@ def geojson_file=(value) end end - def async_discourse_sync - DiscourseOrganizationWorker.perform_async(self.id) - end - - def discourse_sync - DiscourseService::Organization.new(self).sync - end - def formatted_address [address_1, address_2, city, county, postal_code, country].reject(&:blank?).join(", ") end @@ -96,12 +86,6 @@ def country private - def discourse_sync_if_needed - if (changes.keys & ["name", "description"]).present? - async_discourse_sync - end - end - def truncate_blurb self.blurb = blurb[0...250].gsub(/\s+/, ' ').gsub(/\n/," ").strip if blurb_changed? end diff --git a/app/models/project.rb b/app/models/project.rb index d2ec70f7..9ce5c8ba 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -6,7 +6,6 @@ class Project < ActiveRecord::Base enum visibility: { hidden: 0, visible: 1 } before_save :assign_to_lab, :strip_zeroes - after_save :discourse_sync_if_needed, if: Figaro.env.discourse_enabled self.authorizer_name = 'ProjectAuthorizer' @@ -91,14 +90,6 @@ def project_cover nil end - def async_discourse_sync - DiscourseProjectWorker.perform_async(self.id) - end - - def discourse_sync - DiscourseService::Project.new(self).sync - end - protected def total_grades @@ -118,11 +109,4 @@ def assign_to_lab def strip_zeroes self.tag_list.remove("0") end - - def discourse_sync_if_needed - if (changes.keys & ["name", "description"]).present? - async_discourse_sync - end - end - end diff --git a/app/models/user.rb b/app/models/user.rb index b7c06c08..76b29a48 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -91,7 +91,6 @@ def slug_candidates before_create { generate_token(:email_validation_hash) } before_create :downcase_email - after_save :discourse_sync_if_needed, if: Figaro.env.discourse_enabled def avatar_url if avatar_uid.present? @@ -217,10 +216,6 @@ def role_names roles.map(&:name).uniq.join(', ') end - def async_discourse_sync - DiscourseUserSyncWorker.perform_async(self.id) - end - def discourse_profile_url return '' if username.blank? diff --git a/app/views/backstage/labs/show.html.haml b/app/views/backstage/labs/show.html.haml index 5650da51..d6cd9657 100644 --- a/app/views/backstage/labs/show.html.haml +++ b/app/views/backstage/labs/show.html.haml @@ -126,8 +126,6 @@ %pre = @lab.discourse_errors - = comments_script(@lab.discourse_id) - - if current_user.present? - if current_user.has_role? :superadmin = link_to edit_backstage_lab_path(@lab), class: 'btn btn-primary' do diff --git a/app/views/backstage/labs_manager/show.html.haml b/app/views/backstage/labs_manager/show.html.haml index 5650da51..d6cd9657 100644 --- a/app/views/backstage/labs_manager/show.html.haml +++ b/app/views/backstage/labs_manager/show.html.haml @@ -126,8 +126,6 @@ %pre = @lab.discourse_errors - = comments_script(@lab.discourse_id) - - if current_user.present? - if current_user.has_role? :superadmin = link_to edit_backstage_lab_path(@lab), class: 'btn btn-primary' do diff --git a/app/views/labs/show.html.haml b/app/views/labs/show.html.haml index 132ef851..e3a176b3 100644 --- a/app/views/labs/show.html.haml +++ b/app/views/labs/show.html.haml @@ -53,9 +53,3 @@ .row .col-lg-12 = render("academics", lab: @lab, academics: @academics) - - - if @lab.discourse_id.present? - .row.mt-5 - .col-lg-12 - %h3 Discuss this Lab on discuss.fablabs.io - = comments_script(@lab.discourse_id) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index a9f1a835..838e5d1e 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -6,6 +6,3 @@ #main = yield = render 'footer' - - if current_user - - # Automatic login on discourse - %iframe{src: "#{Figaro.env.discourse_endpoint}session/sso", width: '0px', height: '0px', border: 'none'} diff --git a/app/views/machines/show.html.haml b/app/views/machines/show.html.haml index 92de1061..035f99d6 100644 --- a/app/views/machines/show.html.haml +++ b/app/views/machines/show.html.haml @@ -60,10 +60,3 @@ = link_to "Edit", edit_machine_path(@machine), class: 'btn btn-primary' - if current_or_null_user.can_delete?(@machine) = link_to icon('trash-o'), @machine, method: :delete, class: 'btn btn-danger', data: { confirm: "Are you sure?" } - - - .row - .col-lg-12 - - if @machine.discourse_id.present? - %h3 Discuss this Machine on discuss.fablabs.io - = comments_script(@machine.discourse_id) diff --git a/app/views/organizations/show.html.haml b/app/views/organizations/show.html.haml index 15fa053c..61c3ab02 100644 --- a/app/views/organizations/show.html.haml +++ b/app/views/organizations/show.html.haml @@ -41,9 +41,3 @@ .col-lg-4 = render "links", links: @organization.links - - .row - .col-lg-12 - - if @organization.discourse_id.present? - %h3 Discuss this Organization on discuss.fablabs.io - = comments_script(@organization.discourse_id) diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index 00c01438..409ea144 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -60,8 +60,3 @@ = link_to icon('pencil'), edit_project_path(@project), class: 'btn btn-primary' - if current_or_null_user.can_delete?(@project) = link_to icon('trash-o'), @project, method: :delete, class: 'btn btn-danger', data: { confirm: "Are you sure?" } - .row - .col-lg-12 - - if @project.discourse_id.present? - %h3 Discuss this Project on discuss.fablabs.io - = comments_script(@project.discourse_id) diff --git a/lib/tasks/discourse.rake b/lib/tasks/discourse.rake deleted file mode 100644 index c04bf2a2..00000000 --- a/lib/tasks/discourse.rake +++ /dev/null @@ -1,29 +0,0 @@ -namespace :discourse do - - desc 'Sync all sso users with discourse' - task sync_users: :environment do - User.find_each do |user| - user.async_discourse_sync - end - end - desc 'Sync all labs with discourse' - task sync_labs: :environment do - Lab.find_each do |lab| - lab.async_discourse_sync - end - end - - desc 'Sync all machines with discourse' - task sync_machines: :environment do - Machine.find_each do |machine| - machine.async_discourse_sync - end - end - - desc 'Sync all projects with discourse' - task sync_projects: :environment do - Project.find_each do |project| - project.async_discourse_sync - end - end -end