redo the reverted commit

This commit is contained in:
Andrew Brown 2019-05-03 16:29:17 -05:00
parent 106daea496
commit b1f62cccd2
3 changed files with 22 additions and 20 deletions

View File

@ -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?

View File

@ -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)

View File

@ -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|