From b1f62cccd2fbd7b6ce55c5ef0a4b91e1f288fddc Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Fri, 3 May 2019 16:29:17 -0500 Subject: [PATCH] redo the reverted commit --- app/controllers/application_controller.rb | 35 ++++++++++--------- app/controllers/content_controller.rb | 3 +- .../initialize_categories_on_old_accounts.rb | 4 +-- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 377c2ec5..99255f52 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,8 +4,24 @@ class ApplicationController < ActionController::Base before_action :cache_most_used_page_information before_action :cache_forums_unread_counts - # todo name all these methods - before_action do + before_action :set_universe_session + before_action :set_universe_scope + + before_action :set_metadata + + def content_type_from_controller(content_controller_name) + content_controller_name.to_s.chomp('Controller').singularize.constantize + end + + private + + def set_metadata + @page_title ||= '' + @page_keywords ||= %w[writing author nanowrimo novel character fiction fantasy universe creative dnd roleplay larp game design] + @page_description ||= 'Notebook.ai is a set of tools for writers, game designers, and roleplayers to create magnificent universes — and everything within them.' + end + + def set_universe_session if params[:universe].present? && user_signed_in? if params[:universe] == 'all' session.delete(:universe_id) @@ -17,7 +33,7 @@ class ApplicationController < ActionController::Base end end - before_action do + def set_universe_scope if current_user && session[:universe_id] @universe_scope = Universe.find_by(id: session[:universe_id]) @universe_scope = nil unless current_user.universes.include?(@universe_scope) || current_user.contributable_universes.include?(@universe_scope) @@ -26,19 +42,6 @@ class ApplicationController < ActionController::Base end end - before_action do - @page_title ||= '' - @page_keywords ||= %w[writing author nanowrimo novel character fiction fantasy universe creative dnd roleplay larp game design] - @page_description ||= 'Notebook.ai is a set of tools for writers, game designers, and roleplayers to create magnificent universes — and everything within them.' - end - - - def content_type_from_controller(content_controller_name) - content_controller_name.to_s.chomp('Controller').singularize.constantize - end - - private - # Cache some super-common stuff we need for every page. For example, content lists for the side nav. def cache_most_used_page_information return unless user_signed_in? diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index c366ec17..2ed9c60b 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -1,5 +1,4 @@ class ContentController < ApplicationController - # todo before_action :load_content to set @content before_action :authenticate_user!, only: [:index, :new, :create, :edit, :update, :destroy, :deleted, :attributes] before_action :migrate_old_style_field_values, only: [:show, :edit] @@ -150,7 +149,7 @@ class ContentController < ApplicationController end def create - content_type = content_type_from_controller self.class + content_type = content_type_from_controller(self.class) initialize_object unless current_user.can_create?(content_type) diff --git a/script/initialize_categories_on_old_accounts.rb b/script/initialize_categories_on_old_accounts.rb index 5cbe32fa..4aeca66f 100644 --- a/script/initialize_categories_on_old_accounts.rb +++ b/script/initialize_categories_on_old_accounts.rb @@ -5,9 +5,9 @@ ActiveRecord::Base.logger = nil to_migrate = User.all.pluck(:id) - AttributeCategory.pluck(:user_id).uniq users_migrated = 1 -to_migrate.first(100).each do |user_id| +to_migrate.first(50).each do |user_id| user = User.find(user_id) - puts "Migrating user ##{user_id} #{user.email} (#{users_migrated}/#{neg_ids.count})" + puts "Migrating user ##{user_id} #{user.email} (#{users_migrated}/#{to_migrate.count})" ActiveRecord::Base.transaction do Rails.application.config.content_types[:all].each do |content_type|