From f767fa50c2def1b5a8b414d072ee8571a38ebcfc Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Oct 2018 12:31:09 -0500 Subject: [PATCH 01/24] fix a potential 500 when a universe is prompted --- app/controllers/main_controller.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 09ca3920..b365ff09 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -83,10 +83,21 @@ class MainController < ApplicationController def set_random_content @activated_content_types.shuffle.each do |content_type| - if @universe_scope.present? - @content = content_type.constantize.where(user: current_user, universe: @universe_scope).sample + if content_type.downcase == "universe" + if @universe_scope.present? + # when we want to enable prompts for contributing universes we can remove the user: + # selector here, but we will need to verify the user has permission to see the universe + # when we do that, or else prompts could open leak + @content = content_type.constantize.where(user: current_user, id: @universe_scope.id).sample + else + @content = content_type.constantize.where(user: current_user).sample + end else - @content = content_type.constantize.where(user: current_user).sample + if @universe_scope.present? + @content = content_type.constantize.where(user: current_user, universe: @universe_scope).sample + else + @content = content_type.constantize.where(user: current_user).sample + end end return if @content.present? From 5df7895241d1cf78e360b50972a3a1063e47a587 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Oct 2018 12:48:40 -0500 Subject: [PATCH 02/24] add barnes for additional runtime info --- Gemfile | 3 ++- Gemfile.lock | 5 +++++ config/puma.rb | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index fe60c4d6..77faa1d3 100644 --- a/Gemfile +++ b/Gemfile @@ -54,8 +54,9 @@ gem 'slack-notifier' gem 'redcarpet' #markdown formatting # Analytics -gem 'raygun4ruby' +gem 'raygun4ruby' #todo remove gem 'mixpanel-ruby' +gem 'barnes' # Sharing gem 'social-share-button' diff --git a/Gemfile.lock b/Gemfile.lock index a23bb04e..aa2ef4a6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -83,6 +83,9 @@ GEM babel-source (>= 4.0, < 6) execjs (~> 2.0) backports (3.11.3) + barnes (0.0.7) + multi_json (~> 1) + statsd-ruby (~> 1.1) bcrypt (3.1.12) better_errors (2.4.0) coderay (>= 1.0.0) @@ -443,6 +446,7 @@ GEM sprockets (>= 3.0.0) sqlite3 (1.3.13) stackprof (0.2.12) + statsd-ruby (1.4.0) stripe (3.15.0) faraday (~> 0.10) stripe_event (2.1.1) @@ -509,6 +513,7 @@ DEPENDENCIES authority aws-sdk (~> 1.5) aws-sdk-s3 + barnes better_errors binding_of_caller bullet (>= 5.4) diff --git a/config/puma.rb b/config/puma.rb index a41b05bb..c1f291a0 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,5 +1,10 @@ require 'puma/plugin/heroku' +require 'barnes' +before_fork do + Barnes.start +end + workers Integer(ENV['WEB_CONCURRENCY'] || 0) threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5) threads threads_count, threads_count From 4f4a9994e84cd99893ddaac9eb20fdc2b4a7dcde Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Oct 2018 13:57:39 -0500 Subject: [PATCH 03/24] remove raygun --- Gemfile | 1 - Gemfile.lock | 9 --------- config/initializers/raygun.rb | 7 ------- 3 files changed, 17 deletions(-) delete mode 100644 config/initializers/raygun.rb diff --git a/Gemfile b/Gemfile index 77faa1d3..db0af898 100644 --- a/Gemfile +++ b/Gemfile @@ -54,7 +54,6 @@ gem 'slack-notifier' gem 'redcarpet' #markdown formatting # Analytics -gem 'raygun4ruby' #todo remove gem 'mixpanel-ruby' gem 'barnes' diff --git a/Gemfile.lock b/Gemfile.lock index aa2ef4a6..ef4f0e1e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -205,8 +205,6 @@ GEM activesupport (>= 2) nokogiri (>= 1.4) htmlentities (4.3.4) - httparty (0.16.2) - multi_xml (>= 0.5.2) i18n (1.1.0) concurrent-ruby (~> 1.0) inline_svg (1.3.1) @@ -262,7 +260,6 @@ GEM moneta (1.0.0) multi_json (1.13.1) multi_test (0.1.2) - multi_xml (0.6.0) multipart-post (2.0.0) mustache (1.0.5) nenv (0.3.0) @@ -351,11 +348,6 @@ GEM thor (>= 0.18.1, < 2.0) rainbow (3.0.0) rake (12.3.1) - raygun4ruby (2.7.0) - concurrent-ruby - httparty (> 0.13.7) - json - rack rb-fsevent (0.10.3) rb-gravatar (1.0.5) rb-inotify (0.9.10) @@ -555,7 +547,6 @@ DEPENDENCIES rails-perftest rails-ujs rails_12factor - raygun4ruby redcarpet rmagick rspec-prof diff --git a/config/initializers/raygun.rb b/config/initializers/raygun.rb deleted file mode 100644 index 9f8f0498..00000000 --- a/config/initializers/raygun.rb +++ /dev/null @@ -1,7 +0,0 @@ -Raygun.setup do |config| - config.api_key = ENV['RAYGUN_API_KEY'] || '' - config.filter_parameters = Rails.application.config.filter_parameters - - # The default is Rails.env.production? - # config.enable_reporting = !Rails.env.development? && !Rails.env.test? -end From eba5baf0fb83a1415ee1f7ba83c21848c54379a8 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Oct 2018 15:21:59 -0500 Subject: [PATCH 04/24] optimize user#content_list --- README.rdoc | 4 ++-- app/models/concerns/has_content.rb | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.rdoc b/README.rdoc index c3b2623d..764ed5d1 100644 --- a/README.rdoc +++ b/README.rdoc @@ -33,9 +33,9 @@ You'll notice there are *a lot* of issues in *a lot* of milestones. Call it feat TL;DR Milestones are independent of each other -- work on whatever you want to see made! -== Installing the notebook stack locally +== Installing the notebook development stack locally -Install ruby 2.5.1 +Install ruby 2.5.1 (using `rbenv`, `rvm`, any other Ruby version manager, or just plain ol' ruby) rbenv install 2.5.1 diff --git a/app/models/concerns/has_content.rb b/app/models/concerns/has_content.rb index e8bc250f..a8f6d886 100644 --- a/app/models/concerns/has_content.rb +++ b/app/models/concerns/has_content.rb @@ -33,12 +33,18 @@ module HasContent # [..., ...] def content_list - @user_content_list ||= begin - Rails.application.config.content_types[:all].flat_map do |type| - relation = type.name.downcase.pluralize.to_sym # :characters - send(relation) + polymorphic_content_fields = [:id, :name, :universe_id, :created_at, :updated_at, :deleted_at] + + chained_query = nil + @activated_content_types.each do |content_type_class| + if chained_query.nil? + chained_query = content_type_class.select(*polymorphic_content_fields).where(user_id: self.id) + else + chained_query = content_type_class.select(*polymorphic_content_fields).where(user_id: self.id).union(chained_query) end end + + @user_content_list = chained_query end # { From 34acd7f3f673173007e5c13bc9312fb44a2f860f Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Oct 2018 15:59:40 -0500 Subject: [PATCH 05/24] add migrations for unions --- ...017202825_add_page_type_column_to_pages.rb | 23 ++++++++++++++++ ...205546_add_defaults_to_new_page_columns.rb | 26 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 db/migrate/20181017202825_add_page_type_column_to_pages.rb create mode 100644 db/migrate/20181017205546_add_defaults_to_new_page_columns.rb diff --git a/db/migrate/20181017202825_add_page_type_column_to_pages.rb b/db/migrate/20181017202825_add_page_type_column_to_pages.rb new file mode 100644 index 00000000..8db4134b --- /dev/null +++ b/db/migrate/20181017202825_add_page_type_column_to_pages.rb @@ -0,0 +1,23 @@ +class AddPageTypeColumnToPages < ActiveRecord::Migration[5.2] + def change + add_column :universes, :page_type, :string + add_column :characters, :page_type, :string + add_column :countries, :page_type, :string + add_column :creatures, :page_type, :string + add_column :deities, :page_type, :string + add_column :floras, :page_type, :string + add_column :governments, :page_type, :string + add_column :groups, :page_type, :string + add_column :items, :page_type, :string + add_column :landmarks, :page_type, :string + add_column :languages, :page_type, :string + add_column :locations, :page_type, :string + add_column :magics, :page_type, :string + add_column :planets, :page_type, :string + add_column :races, :page_type, :string + add_column :religions, :page_type, :string + add_column :scenes, :page_type, :string + add_column :technologies, :page_type, :string + add_column :towns, :page_type, :string + end +end diff --git a/db/migrate/20181017205546_add_defaults_to_new_page_columns.rb b/db/migrate/20181017205546_add_defaults_to_new_page_columns.rb new file mode 100644 index 00000000..7b9e5f9c --- /dev/null +++ b/db/migrate/20181017205546_add_defaults_to_new_page_columns.rb @@ -0,0 +1,26 @@ +class AddDefaultsToNewPageColumns < ActiveRecord::Migration[5.2] + def up + change_column :universes, :page_type, :string, default: 'Universe' + change_column :characters, :page_type, :string, default: 'Character' + change_column :countries, :page_type, :string, default: 'Country' + change_column :creatures, :page_type, :string, default: 'Creature' + change_column :deities, :page_type, :string, default: 'Deity' + change_column :floras, :page_type, :string, default: 'Flora' + change_column :governments, :page_type, :string, default: 'Government' + change_column :groups, :page_type, :string, default: 'Group' + change_column :items, :page_type, :string, default: 'Item' + change_column :landmarks, :page_type, :string, default: 'Landmark' + change_column :languages, :page_type, :string, default: 'Language' + change_column :locations, :page_type, :string, default: 'Location' + change_column :magics, :page_type, :string, default: 'Magic' + change_column :planets, :page_type, :string, default: 'Planet' + change_column :races, :page_type, :string, default: 'Race' + change_column :religions, :page_type, :string, default: 'Religion' + change_column :scenes, :page_type, :string, default: 'Scene' + change_column :technologies, :page_type, :string, default: 'Technology' + change_column :towns, :page_type, :string, default: 'Town' + end + + def down + end +end From ac4b230637bfbf9723566dd4dcc32ced11ed29e7 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Oct 2018 16:07:48 -0500 Subject: [PATCH 06/24] same --- ...205546_add_defaults_to_new_page_columns.rb | 43 +++++++++---------- db/schema.rb | 21 ++++++++- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/db/migrate/20181017205546_add_defaults_to_new_page_columns.rb b/db/migrate/20181017205546_add_defaults_to_new_page_columns.rb index 7b9e5f9c..2ebd1a21 100644 --- a/db/migrate/20181017205546_add_defaults_to_new_page_columns.rb +++ b/db/migrate/20181017205546_add_defaults_to_new_page_columns.rb @@ -1,26 +1,23 @@ class AddDefaultsToNewPageColumns < ActiveRecord::Migration[5.2] - def up - change_column :universes, :page_type, :string, default: 'Universe' - change_column :characters, :page_type, :string, default: 'Character' - change_column :countries, :page_type, :string, default: 'Country' - change_column :creatures, :page_type, :string, default: 'Creature' - change_column :deities, :page_type, :string, default: 'Deity' - change_column :floras, :page_type, :string, default: 'Flora' - change_column :governments, :page_type, :string, default: 'Government' - change_column :groups, :page_type, :string, default: 'Group' - change_column :items, :page_type, :string, default: 'Item' - change_column :landmarks, :page_type, :string, default: 'Landmark' - change_column :languages, :page_type, :string, default: 'Language' - change_column :locations, :page_type, :string, default: 'Location' - change_column :magics, :page_type, :string, default: 'Magic' - change_column :planets, :page_type, :string, default: 'Planet' - change_column :races, :page_type, :string, default: 'Race' - change_column :religions, :page_type, :string, default: 'Religion' - change_column :scenes, :page_type, :string, default: 'Scene' - change_column :technologies, :page_type, :string, default: 'Technology' - change_column :towns, :page_type, :string, default: 'Town' - end - - def down + def change + change_column_default :universes, :page_type, 'Universe' + change_column_default :characters, :page_type, 'Character' + change_column_default :countries, :page_type, 'Country' + change_column_default :creatures, :page_type, 'Creature' + change_column_default :deities, :page_type, 'Deity' + change_column_default :floras, :page_type, 'Flora' + change_column_default :governments, :page_type, 'Government' + change_column_default :groups, :page_type, 'Group' + change_column_default :items, :page_type, 'Item' + change_column_default :landmarks, :page_type, 'Landmark' + change_column_default :languages, :page_type, 'Language' + change_column_default :locations, :page_type, 'Location' + change_column_default :magics, :page_type, 'Magic' + change_column_default :planets, :page_type, 'Planet' + change_column_default :races, :page_type, 'Race' + change_column_default :religions, :page_type, 'Religion' + change_column_default :scenes, :page_type, 'Scene' + change_column_default :technologies, :page_type, 'Technology' + change_column_default :towns, :page_type, 'Town' end end diff --git a/db/schema.rb b/db/schema.rb index 36e925bd..3b5f5dbd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_09_24_164517) do +ActiveRecord::Schema.define(version: 2018_10_17_205546) do create_table "api_keys", force: :cascade do |t| t.integer "user_id" @@ -269,6 +269,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.string "hobbies" t.string "personality_type" t.datetime "deleted_at" + t.string "page_type", default: "Character" t.index ["deleted_at", "id"], name: "index_characters_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_characters_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_characters_on_deleted_at_and_user_id" @@ -327,6 +328,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.datetime "deleted_at" t.string "privacy" t.integer "user_id" + t.string "page_type", default: "Country" t.index ["deleted_at", "id"], name: "index_countries_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_countries_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_countries_on_deleted_at_and_user_id" @@ -469,6 +471,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.string "family" t.string "genus" t.string "species" + t.string "page_type", default: "Creature" t.index ["deleted_at", "id"], name: "index_creatures_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_creatures_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_creatures_on_deleted_at_and_user_id" @@ -508,6 +511,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.datetime "deleted_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "page_type", default: "Deity" t.index ["deleted_at", "id"], name: "index_deities_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_deities_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_deities_on_deleted_at_and_user_id" @@ -777,6 +781,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.string "privacy" t.datetime "deleted_at" t.string "material_uses" + t.string "page_type", default: "Flora" t.index ["deleted_at", "id"], name: "index_floras_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_floras_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_floras_on_deleted_at_and_user_id" @@ -895,6 +900,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.datetime "deleted_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "page_type", default: "Government" t.index ["deleted_at", "id"], name: "index_governments_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_governments_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_governments_on_deleted_at_and_user_id" @@ -985,6 +991,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.datetime "updated_at", null: false t.string "privacy" t.datetime "deleted_at" + t.string "page_type", default: "Group" t.index ["deleted_at", "id"], name: "index_groups_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_groups_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_groups_on_deleted_at_and_user_id" @@ -1044,6 +1051,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.datetime "updated_at" t.string "privacy", default: "private", null: false t.datetime "deleted_at" + t.string "page_type", default: "Item" t.index ["deleted_at", "id"], name: "index_items_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_items_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_items_on_deleted_at_and_user_id" @@ -1118,6 +1126,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.datetime "deleted_at" t.string "privacy" t.integer "user_id" + t.string "page_type", default: "Landmark" t.index ["deleted_at", "id"], name: "index_landmarks_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_landmarks_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_landmarks_on_deleted_at_and_user_id" @@ -1144,6 +1153,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.datetime "updated_at", null: false t.string "privacy" t.datetime "deleted_at" + t.string "page_type", default: "Language" t.index ["deleted_at", "id"], name: "index_languages_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_languages_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_languages_on_deleted_at_and_user_id" @@ -1252,6 +1262,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.string "founding_story" t.string "sports" t.datetime "deleted_at" + t.string "page_type", default: "Location" t.index ["deleted_at", "id"], name: "index_locations_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_locations_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_locations_on_deleted_at_and_user_id" @@ -1288,6 +1299,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.datetime "updated_at", null: false t.string "privacy" t.datetime "deleted_at" + t.string "page_type", default: "Magic" t.index ["deleted_at", "id"], name: "index_magics_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_magics_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_magics_on_deleted_at_and_user_id" @@ -1508,6 +1520,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "notes" + t.string "page_type", default: "Planet" t.index ["deleted_at", "id"], name: "index_planets_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_planets_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_planets_on_deleted_at_and_user_id" @@ -1544,6 +1557,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.datetime "updated_at", null: false t.string "privacy" t.datetime "deleted_at" + t.string "page_type", default: "Race" t.index ["deleted_at", "id"], name: "index_races_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_races_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_races_on_deleted_at_and_user_id" @@ -1612,6 +1626,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.datetime "updated_at", null: false t.string "privacy" t.datetime "deleted_at" + t.string "page_type", default: "Religion" t.index ["deleted_at", "id"], name: "index_religions_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_religions_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_religions_on_deleted_at_and_user_id" @@ -1672,6 +1687,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.datetime "updated_at", null: false t.string "privacy" t.datetime "deleted_at" + t.string "page_type", default: "Scene" t.index ["deleted_at", "id"], name: "index_scenes_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_scenes_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_scenes_on_deleted_at_and_user_id" @@ -1755,6 +1771,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.datetime "deleted_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "page_type", default: "Technology" t.index ["deleted_at", "id"], name: "index_technologies_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_technologies_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_technologies_on_deleted_at_and_user_id" @@ -2181,6 +2198,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.datetime "deleted_at" t.string "privacy" t.integer "user_id" + t.string "page_type", default: "Town" t.index ["deleted_at", "id"], name: "index_towns_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_towns_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_towns_on_deleted_at_and_user_id" @@ -2203,6 +2221,7 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.string "technology" t.string "genre" t.datetime "deleted_at" + t.string "page_type", default: "Universe" t.index ["deleted_at", "id"], name: "index_universes_on_deleted_at_and_id" t.index ["deleted_at", "user_id"], name: "index_universes_on_deleted_at_and_user_id" t.index ["deleted_at"], name: "index_universes_on_deleted_at" From c7f5f85508c2596b25fa0a2596684552e075da64 Mon Sep 17 00:00:00 2001 From: Euan Kemp Date: Wed, 17 Oct 2018 14:18:36 -0700 Subject: [PATCH 07/24] update materialize.css to 1.0.0 from 1.0.0-beta This change just seems like it's worth doing. Presumably it was last updated before 1.0.0 was released. --- app/views/layouts/_common_head.html.erb | 4 ++-- app/views/layouts/forum.html.erb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/layouts/_common_head.html.erb b/app/views/layouts/_common_head.html.erb index 4e1e71bc..3db3f207 100644 --- a/app/views/layouts/_common_head.html.erb +++ b/app/views/layouts/_common_head.html.erb @@ -2,14 +2,14 @@ <%= csrf_meta_tags %> <%= stylesheet_link_tag 'application' %> - + - + diff --git a/app/views/layouts/forum.html.erb b/app/views/layouts/forum.html.erb index d7d94430..822a44cf 100644 --- a/app/views/layouts/forum.html.erb +++ b/app/views/layouts/forum.html.erb @@ -2,14 +2,14 @@ <%= stylesheet_link_tag 'application' %> - + - + <%= render 'layouts/favicon' %> From d25ae12c08e27b8306166adbffa66dbc1b3bb850 Mon Sep 17 00:00:00 2001 From: Euan Kemp Date: Wed, 17 Oct 2018 14:20:15 -0700 Subject: [PATCH 08/24] Fix checkboxes to use materialize checkboxes Before there was a hack in place to not use materialize checkboxes because the actual checkbox didn't show up. This re-arranges all the checkboxes I could find to work with materialize, thus allowing the hack to be safely removed. The forum (namely preferences) continue to use the hacky checkbox, but that hack is maintained separately and still seems to work with this change. --- app/assets/stylesheets/fixes.scss | 11 ----------- app/views/devise/registrations/new.html.erb | 6 +++--- .../registrations/panes/_preferences.html.erb | 8 ++++---- app/views/devise/sessions/_form.html.erb | 14 +++++++++----- db/schema.rb | 1 - 5 files changed, 16 insertions(+), 24 deletions(-) delete mode 100644 app/assets/stylesheets/fixes.scss diff --git a/app/assets/stylesheets/fixes.scss b/app/assets/stylesheets/fixes.scss deleted file mode 100644 index 2b2360e5..00000000 --- a/app/assets/stylesheets/fixes.scss +++ /dev/null @@ -1,11 +0,0 @@ -/* - * These are temporary fixes and/or hacks for issues seen in prod. Every line here - * should be assumed temporary and with an inherit desire to remove it with something - * cleaner. - */ - -// For some reason, the latest materializecss hides checkboxes. This un-hides them. -input[type="checkbox"]:not(:checked), input[type="checkbox"]:checked { - position: inherit !important; - opacity: inherit !important; -} diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index c93db901..09deac81 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -60,10 +60,10 @@ %>
- <%= f.check_box :email_updates %> <%= f.label :email_updates do %> - We're always working to improve Notebook.ai. Please leave this box checked if you'd like to receive occasional updates about - what's new. + <%= f.check_box :email_updates %> + We're always working to improve Notebook.ai. Please leave this box checked if you'd like to receive occasional updates about + what's new. <% end %>
diff --git a/app/views/devise/registrations/panes/_preferences.html.erb b/app/views/devise/registrations/panes/_preferences.html.erb index 27f13d0c..7b60ba41 100644 --- a/app/views/devise/registrations/panes/_preferences.html.erb +++ b/app/views/devise/registrations/panes/_preferences.html.erb @@ -2,9 +2,9 @@

Your Notebook.ai design

- <%= f.check_box :fluid_preference %> <%= f.label :fluid_preference do %> - I want to use full-width Notebook.ai. Great for small screens, but not so much for very large ones. + <%= f.check_box :fluid_preference %> + I want to use full-width Notebook.ai. Great for small screens, but not so much for very large ones. <% end %>
@@ -14,9 +14,9 @@

Email preferences

- <%= f.check_box :email_updates %> <%= f.label :email_updates do %> - I want to receive occasional updates by email about new Notebook.ai features. + <%= f.check_box :email_updates %> + I want to receive occasional updates by email about new Notebook.ai features. <% end %>
diff --git a/app/views/devise/sessions/_form.html.erb b/app/views/devise/sessions/_form.html.erb index a97e885e..4712947a 100644 --- a/app/views/devise/sessions/_form.html.erb +++ b/app/views/devise/sessions/_form.html.erb @@ -13,17 +13,21 @@
+
<% if devise_mapping.rememberable? -%> - + <%= f.label :remember_me do %> <%= f.check_box :remember_me %> - <%= f.label :remember_me %> - + Remember me + <% end %> <% end -%> - <%= f.submit "Log in", class: 'btn blue' %> +
+
+ <%= f.submit "Log in", class: 'btn blue' %> +


<%= render "devise/shared/links" %>

-<% end %> \ No newline at end of file +<% end %> diff --git a/db/schema.rb b/db/schema.rb index 36e925bd..1f712673 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1958,7 +1958,6 @@ ActiveRecord::Schema.define(version: 2018_09_24_164517) do t.datetime "updated_at", null: false t.index ["messageboard_id"], name: "index_thredded_posts_on_messageboard_id" t.index ["moderation_state", "updated_at"], name: "index_thredded_posts_for_display" - t.index ["postable_id"], name: "index_thredded_posts_on_postable_id" t.index ["postable_id"], name: "index_thredded_posts_on_postable_id_and_postable_type" t.index ["user_id"], name: "index_thredded_posts_on_user_id" end From 8ce85f6edaadc145b19e67d04c185005a35c2f1d Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Oct 2018 16:52:05 -0500 Subject: [PATCH 09/24] mad rad optimizations --- app/controllers/application_controller.rb | 7 +--- app/models/concerns/has_content.rb | 48 ++++++++--------------- 2 files changed, 19 insertions(+), 36 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index efbc52b9..5c95affe 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -43,13 +43,10 @@ class ApplicationController < ActionController::Base return unless user_signed_in? @activated_content_types = ( - Rails.application.config.content_types[:all].map(&:name) & # Use config to dictate order + Rails.application.config.content_types[:all].map(&:name) & # Use config to dictate order, but AND to only include what a user has turned on current_user.user_content_type_activators.pluck(:content_type) ) - @current_user_content = {} - @activated_content_types.each do |content_type| - @current_user_content[content_type] = content_type.constantize.where(user: current_user).to_a - end + @current_user_content = current_user.content(content_types: @activated_content_types) end end diff --git a/app/models/concerns/has_content.rb b/app/models/concerns/has_content.rb index a8f6d886..5121baa2 100644 --- a/app/models/concerns/has_content.rb +++ b/app/models/concerns/has_content.rb @@ -19,32 +19,31 @@ module HasContent # characters: [...], # locations: [...] # } - def content - @user_content ||= begin - content_value = {} - Rails.application.config.content_types[:all].each do |type| - relation = type.name.downcase.pluralize.to_sym # :characters - content_value[relation] = send(relation) - end - - content_value - end + def content( + content_types: Rails.application.config.content_types[:all].map(&:name), + page_scoping: { user_id: self.id } + ) + @user_content ||= content_list(page_scoping: page_scoping, content_types: content_types).group_by(&:page_type) end # [..., ...] - def content_list - polymorphic_content_fields = [:id, :name, :universe_id, :created_at, :updated_at, :deleted_at] + def content_list( + content_types: Rails.application.config.content_types[:all].map(&:name), + page_scoping: { user_id: self.id } + ) + polymorphic_content_fields = [:id, :name, :page_type, :user_id, :universe_id, :created_at, :updated_at, :deleted_at] chained_query = nil - @activated_content_types.each do |content_type_class| + content_types.each do |content_type| + content_type_class = content_type.constantize if chained_query.nil? - chained_query = content_type_class.select(*polymorphic_content_fields).where(user_id: self.id) + chained_query = content_type_class.select(*polymorphic_content_fields).where(page_scoping) else - chained_query = content_type_class.select(*polymorphic_content_fields).where(user_id: self.id).union(chained_query) + chained_query = content_type_class.select(*polymorphic_content_fields).where(page_scoping).union(chained_query) end end - @user_content_list = chained_query + @user_content_list ||= chained_query end # { @@ -52,25 +51,12 @@ module HasContent # locations: [...] # } def content_in_universe universe_id - @user_content_in_universe ||= begin - content_value = {} - Rails.application.config.content_types[:all_non_universe].each do |type| - relation = type.name.downcase.pluralize.to_sym # :characters - content_value[relation] = send(relation).in_universe(universe_id) - end - - content_value - end + @user_content_in_universe ||= content_list(page_scoping: { user_id: self.id, universe_id: universe_id }).group_by(&:page_type) end # 5 def content_count - @user_content_count ||= begin - Rails.application.config.content_types[:all].map do |type| - relation = type.name.downcase.pluralize.to_sym # :characters - send(relation).count - end.sum - end + @user_content_count ||= content_list.count end # { From b5612eddda25be03feefde40ccecabb7eda4a15f Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Oct 2018 16:53:55 -0500 Subject: [PATCH 10/24] safety around empty content --- app/views/layouts/_sidenav.html.erb | 2 +- app/views/main/dashboard.html.erb | 2 +- app/views/universes/_picker.html.erb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/layouts/_sidenav.html.erb b/app/views/layouts/_sidenav.html.erb index 31ada4c6..6bcacc8a 100644 --- a/app/views/layouts/_sidenav.html.erb +++ b/app/views/layouts/_sidenav.html.erb @@ -93,7 +93,7 @@ @universe_scope.send(pluralized_name).count else ( - @current_user_content[content_type] + + @current_user_content[content_type] || [] + current_user.send("contributable_#{pluralized_name}") + (content_type_klass == Universe ? [] : content_type_klass.where(universe_id: current_user.universes.pluck(:id))) ).uniq.count diff --git a/app/views/main/dashboard.html.erb b/app/views/main/dashboard.html.erb index 929b9983..019366c5 100644 --- a/app/views/main/dashboard.html.erb +++ b/app/views/main/dashboard.html.erb @@ -21,7 +21,7 @@ if @universe_scope.present? && content_type != 'Universe' content_list = @universe_scope.send(pluralized_content_name) else - content_list = @current_user_content[content_type] + + content_list = @current_user_content[content_type] || [] + current_user.send("contributable_#{pluralized_content_name}") # todo I don't think this is actually necessary anymore, but leaving around for a few days just in case diff --git a/app/views/universes/_picker.html.erb b/app/views/universes/_picker.html.erb index b4040db4..a3e9e456 100644 --- a/app/views/universes/_picker.html.erb +++ b/app/views/universes/_picker.html.erb @@ -20,7 +20,7 @@
  • <%= link_to "All universes", "?universe=all" %>
  • <% if current_user %>
  • - <% (@current_user_content['Universe'] + current_user.contributable_universes).sort_by(&:name).each do |universe| %> + <% ((@current_user_content['Universe'] || []) + current_user.contributable_universes).sort_by(&:name).each do |universe| %>
  • <%= link_to universe.name + (universe.user_id == current_user.id ? '' : ' (contributor)'), "?universe=#{universe.id}" %>
  • <% end %> <% end %> From 947d7efb7f240d14dc949586e7d6f6a6a57b72f2 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Oct 2018 17:58:48 -0500 Subject: [PATCH 11/24] Create polymorphic ContentPages --- app/controllers/export_controller.rb | 9 ++++----- app/models/concerns/has_content.rb | 4 ++-- app/models/content_page.rb | 4 ++++ app/views/main/dashboard.html.erb | 5 ----- .../20181017224014_create_content_pages.rb | 15 +++++++++++++++ db/schema.rb | 16 +++++++++++++++- test/fixtures/content_pages.yml | 19 +++++++++++++++++++ test/models/content_page_test.rb | 7 +++++++ 8 files changed, 66 insertions(+), 13 deletions(-) create mode 100644 app/models/content_page.rb create mode 100644 db/migrate/20181017224014_create_content_pages.rb create mode 100644 test/fixtures/content_pages.yml create mode 100644 test/models/content_page_test.rb diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb index ff3fd13d..7edd9268 100644 --- a/app/controllers/export_controller.rb +++ b/app/controllers/export_controller.rb @@ -27,13 +27,13 @@ class ExportController < ApplicationController def notebook_json report_to_mixpanel 'json', 'notebook' - json_dump = current_user.content.map { |category, content| {"#{category}": fill_relations(content)} }.to_json + json_dump = current_user.content.map { |category, content| {"#{category}": fill_relations(category.constantize, content)} }.to_json send_data json_dump, filename: "notebook-#{Date.today}.json" end def notebook_xml report_to_mixpanel 'xml', 'notebook' - xml_dump = current_user.content.map { |category, content| {"#{category}": fill_relations(content)}}.to_xml + xml_dump = current_user.content.map { |category, content| {"#{category}": fill_relations(category.constantize, content)}}.to_xml send_data xml_dump, filename: "notebook-#{Date.today}.xml" end @@ -88,8 +88,7 @@ class ExportController < ApplicationController end end - def fill_relations ar_relation - ar_class = ar_relation.build.class + def fill_relations(ar_class, ar_relation) attribute_categories = ar_class.attribute_categories(current_user) ar_relation.map do |content| @@ -99,7 +98,7 @@ class ExportController < ApplicationController begin value = content.send(attr.name) rescue - value = Attribute.where(user: current_user, attribute_field: attr, entity: content).first + value = Attribute.find_by(user: current_user, attribute_field: attr, entity_id: content.id, entity_type: ar_class.name) value = value.value if value end next if value.nil? || value.blank? diff --git a/app/models/concerns/has_content.rb b/app/models/concerns/has_content.rb index 5121baa2..a09c194f 100644 --- a/app/models/concerns/has_content.rb +++ b/app/models/concerns/has_content.rb @@ -31,10 +31,10 @@ module HasContent content_types: Rails.application.config.content_types[:all].map(&:name), page_scoping: { user_id: self.id } ) - polymorphic_content_fields = [:id, :name, :page_type, :user_id, :universe_id, :created_at, :updated_at, :deleted_at] + polymorphic_content_fields = [:id, :name, :page_type, :user_id, :universe_id, :created_at, :updated_at, :deleted_at, :privacy] chained_query = nil - content_types.each do |content_type| + (content_types + ["ContentPage"]).each do |content_type| content_type_class = content_type.constantize if chained_query.nil? chained_query = content_type_class.select(*polymorphic_content_fields).where(page_scoping) diff --git a/app/models/content_page.rb b/app/models/content_page.rb new file mode 100644 index 00000000..99c38854 --- /dev/null +++ b/app/models/content_page.rb @@ -0,0 +1,4 @@ +class ContentPage < ApplicationRecord + belongs_to :user + belongs_to :universe +end diff --git a/app/views/main/dashboard.html.erb b/app/views/main/dashboard.html.erb index 019366c5..a912adc7 100644 --- a/app/views/main/dashboard.html.erb +++ b/app/views/main/dashboard.html.erb @@ -23,11 +23,6 @@ else content_list = @current_user_content[content_type] || [] + current_user.send("contributable_#{pluralized_content_name}") - - # todo I don't think this is actually necessary anymore, but leaving around for a few days just in case - # if content_type != 'Universe' - # content_list.concat(content_type.constantize.where(universe_id: current_user_universe_ids)) - # end end content_list = content_list.uniq diff --git a/db/migrate/20181017224014_create_content_pages.rb b/db/migrate/20181017224014_create_content_pages.rb new file mode 100644 index 00000000..ef8c6111 --- /dev/null +++ b/db/migrate/20181017224014_create_content_pages.rb @@ -0,0 +1,15 @@ +class CreateContentPages < ActiveRecord::Migration[5.2] + def change + create_table :content_pages do |t| + t.string :name + t.string :description + t.references :user, foreign_key: true + t.references :universe, foreign_key: true + t.datetime :deleted_at + t.string :privacy + t.string :page_type + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 3b5f5dbd..0d20bf39 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_10_17_205546) do +ActiveRecord::Schema.define(version: 2018_10_17_224014) do create_table "api_keys", force: :cascade do |t| t.integer "user_id" @@ -296,6 +296,20 @@ ActiveRecord::Schema.define(version: 2018_10_17_205546) do t.index ["user_id"], name: "index_content_change_events_on_user_id" end + create_table "content_pages", force: :cascade do |t| + t.string "name" + t.string "description" + t.integer "user_id" + t.integer "universe_id" + t.datetime "deleted_at" + t.string "privacy" + t.string "page_type" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["universe_id"], name: "index_content_pages_on_universe_id" + t.index ["user_id"], name: "index_content_pages_on_user_id" + end + create_table "contributors", force: :cascade do |t| t.integer "universe_id" t.string "email" diff --git a/test/fixtures/content_pages.yml b/test/fixtures/content_pages.yml new file mode 100644 index 00000000..24361b4a --- /dev/null +++ b/test/fixtures/content_pages.yml @@ -0,0 +1,19 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + description: MyString + user: one + universe: one + deleted_at: 2018-10-17 17:40:14 + privacy: MyString + page_type: MyString + +two: + name: MyString + description: MyString + user: two + universe: two + deleted_at: 2018-10-17 17:40:14 + privacy: MyString + page_type: MyString diff --git a/test/models/content_page_test.rb b/test/models/content_page_test.rb new file mode 100644 index 00000000..a798e661 --- /dev/null +++ b/test/models/content_page_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ContentPageTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 68445754e32d7e629b49befeccfd3bc046c1da3f Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Oct 2018 18:20:42 -0500 Subject: [PATCH 12/24] specify page type in polymorphic paths --- app/views/content/cards/_in_universe_content_list.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/content/cards/_in_universe_content_list.html.erb b/app/views/content/cards/_in_universe_content_list.html.erb index 9489489d..7f6de3fa 100644 --- a/app/views/content/cards/_in_universe_content_list.html.erb +++ b/app/views/content/cards/_in_universe_content_list.html.erb @@ -81,11 +81,11 @@ <% content_list.each do |content| %> - <%= link_to list_name_lookup_cache[content.id].presence || content.name, polymorphic_path(content) %> + <%= link_to list_name_lookup_cache[content.id].presence || content.name, polymorphic_path(content.page_type.downcase, id: content.id) %> <%# truncate(content.description, length: 200) %>
    - <%= link_to edit_polymorphic_path(content) do %> + <%= link_to edit_polymorphic_path(content.page_type.downcase, id: content.id) do %> edit <% end %>
    From 5f8ca60e9bd4a77fe9efad6c129c5fafddcd088a Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Oct 2018 18:32:24 -0500 Subject: [PATCH 13/24] use up to date names on recent content page --- app/controllers/main_controller.rb | 12 ++++++------ app/views/content/list/_list.html.erb | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index b365ff09..c5b8837b 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -36,20 +36,20 @@ class MainController < ApplicationController end def recent_content - content_types = Rails.application.config.content_types[:all] - # todo optimize this / use Attributes - @recent_edits = content_types.flat_map { |klass| - klass.where(user_id: current_user.id) + @recent_edits = @activated_content_types.flat_map { |klass| + klass.constantize + .where(user_id: current_user.id) .order(updated_at: :desc) .limit(100) }.sort_by(&:updated_at) .last(100) .reverse - @recent_creates = content_types.flat_map { |klass| - klass.where(user_id: current_user.id) + @recent_creates = @activated_content_types.flat_map { |klass| + klass.constantize + .where(user_id: current_user.id) .order(created_at: :desc) .limit(100) }.sort_by(&:created_at) diff --git a/app/views/content/list/_list.html.erb b/app/views/content/list/_list.html.erb index ca680bf7..f94ba284 100644 --- a/app/views/content/list/_list.html.erb +++ b/app/views/content/list/_list.html.erb @@ -28,7 +28,7 @@ <%= content.class.icon %> <% end %> - <%= link_to (content.respond_to?(:label) ? content.label : list_name_lookup_cache[content.id].presence || content.name), content %> + <%= link_to content.name, content %> <% universe_field_value = content.universe_field_value %> <% if universe_field_value.present? %> @@ -77,7 +77,7 @@ <% if user_signed_in? && content.user_id == current_user.id %> <%# todo also show if you're a contributor %> - <%= link_to edit_polymorphic_path(content), class: 'js-edit-hover' do %> + <%= link_to edit_polymorphic_path(content.page_type.downcase, id: content.id), class: 'js-edit-hover' do %> edit <% end %> <% end %> From 263093ad80d5f6e4c377ac8cc62c00e6eb35043c Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Oct 2018 18:35:40 -0500 Subject: [PATCH 14/24] use name field for recent content names again, but with bugfiz --- app/views/content/list/_list.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/content/list/_list.html.erb b/app/views/content/list/_list.html.erb index f94ba284..774e9724 100644 --- a/app/views/content/list/_list.html.erb +++ b/app/views/content/list/_list.html.erb @@ -10,7 +10,7 @@ list_name_lookup_cache = Hash[ name_field.attribute_values.where( entity_type: content_type.name - ).pluck(:entity_id, :value) + ).pluck(:entity_type, :entity_id, :value).map { |pt, id, v| ["#{pt}_#{id}", v]} ] else list_name_lookup_cache = {} @@ -28,7 +28,7 @@ <%= content.class.icon %> <% end %> - <%= link_to content.name, content %> + <%= link_to (content.respond_to?(:label) ? content.label : list_name_lookup_cache["#{content.page_type}_#{content.id}"].presence || content.name), content %> <% universe_field_value = content.universe_field_value %> <% if universe_field_value.present? %> From 6085a4aac220e5d8191bc7d1e5964bc20073c9a7 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Oct 2018 23:56:30 -0500 Subject: [PATCH 15/24] better readability --- app/views/content/list/_list.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/content/list/_list.html.erb b/app/views/content/list/_list.html.erb index 774e9724..49c34110 100644 --- a/app/views/content/list/_list.html.erb +++ b/app/views/content/list/_list.html.erb @@ -10,7 +10,7 @@ list_name_lookup_cache = Hash[ name_field.attribute_values.where( entity_type: content_type.name - ).pluck(:entity_type, :entity_id, :value).map { |pt, id, v| ["#{pt}_#{id}", v]} + ).pluck(:entity_type, :entity_id, :value).map { |page_type, page_id, value| ["#{page_type}_#{page_id}", value]} ] else list_name_lookup_cache = {} From a5aae5f035dec6192866f3279a673d606f188a48 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 18 Oct 2018 00:15:13 -0500 Subject: [PATCH 16/24] don't query universe.universe_id --- app/models/concerns/has_content.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/has_content.rb b/app/models/concerns/has_content.rb index a09c194f..6a95abc9 100644 --- a/app/models/concerns/has_content.rb +++ b/app/models/concerns/has_content.rb @@ -31,10 +31,14 @@ module HasContent content_types: Rails.application.config.content_types[:all].map(&:name), page_scoping: { user_id: self.id } ) - polymorphic_content_fields = [:id, :name, :page_type, :user_id, :universe_id, :created_at, :updated_at, :deleted_at, :privacy] chained_query = nil (content_types + ["ContentPage"]).each do |content_type| + if content_type.downcase == "universe" + polymorphic_content_fields = [:id, :name, :page_type, :user_id, :created_at, :updated_at, :deleted_at, :privacy] + else + polymorphic_content_fields = [:id, :name, :page_type, :user_id, :universe_id, :created_at, :updated_at, :deleted_at, :privacy] + end content_type_class = content_type.constantize if chained_query.nil? chained_query = content_type_class.select(*polymorphic_content_fields).where(page_scoping) From 1ab48c1336810b996529cb362b8d8f6c58882978 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 18 Oct 2018 00:19:10 -0500 Subject: [PATCH 17/24] fix --- app/models/concerns/has_content.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/models/concerns/has_content.rb b/app/models/concerns/has_content.rb index 6a95abc9..a72b590e 100644 --- a/app/models/concerns/has_content.rb +++ b/app/models/concerns/has_content.rb @@ -31,14 +31,11 @@ module HasContent content_types: Rails.application.config.content_types[:all].map(&:name), page_scoping: { user_id: self.id } ) + # todo we can't select for universe_id here which kind of sucks, so we need to research 1) the repercussions, 2) what to do instead + polymorphic_content_fields = [:id, :name, :page_type, :user_id, :created_at, :updated_at, :deleted_at, :privacy] chained_query = nil (content_types + ["ContentPage"]).each do |content_type| - if content_type.downcase == "universe" - polymorphic_content_fields = [:id, :name, :page_type, :user_id, :created_at, :updated_at, :deleted_at, :privacy] - else - polymorphic_content_fields = [:id, :name, :page_type, :user_id, :universe_id, :created_at, :updated_at, :deleted_at, :privacy] - end content_type_class = content_type.constantize if chained_query.nil? chained_query = content_type_class.select(*polymorphic_content_fields).where(page_scoping) From d306ab1dc007540f1fda381a698cee7508d7ed17 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 18 Oct 2018 00:45:43 -0500 Subject: [PATCH 18/24] todo --- app/views/content/list/_list.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/content/list/_list.html.erb b/app/views/content/list/_list.html.erb index 49c34110..0ac06680 100644 --- a/app/views/content/list/_list.html.erb +++ b/app/views/content/list/_list.html.erb @@ -86,6 +86,7 @@ <% end %> <% if local_assigns[:show_add_another_form] && content_list.any? && current_user.can_create?(content_type) %> + <%# todo real permissions here %> <% if content_type == Character || content_type == Location || content_type == Item || current_user.on_premium_plan? %> <% unless content_type == Universe %> <%= render partial: 'content/list/quick_add_form', locals: { content_type: content_type } %> From e2009b56e29ccf9ded0e9af7ab773dbd18748d9b Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 18 Oct 2018 10:38:01 -0500 Subject: [PATCH 19/24] todo --- app/views/cards/user/_recent_activity.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/cards/user/_recent_activity.html.erb b/app/views/cards/user/_recent_activity.html.erb index 717c3902..5b115de1 100644 --- a/app/views/cards/user/_recent_activity.html.erb +++ b/app/views/cards/user/_recent_activity.html.erb @@ -5,7 +5,7 @@ locals: { title: defined?(title) ? title : 'Recent creations', content_list: content_list, - content_type: Character + content_type: Character # todo why is this hard-coded? } %> From 9e21ef173e89ddca4fdba0c391866bfbb38b8037 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 18 Oct 2018 11:47:32 -0500 Subject: [PATCH 20/24] fix search --- app/controllers/search_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 46c6904f..c361c667 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -29,6 +29,8 @@ class SearchController < ApplicationController related_controller.send(:content_param_list).select do |attribute| !attribute.is_a?(Hash) && searchable_attribute?(attribute.to_s) end + rescue NameError # If we don't have a controller for a particular content type, treat it as no results + [] end # Returns whether or not a particular attribute should be included on searches. From 454a72b10411303e95db849535a4f9be92ac3c40 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 18 Oct 2018 12:44:15 -0500 Subject: [PATCH 21/24] debug if someone upgrades to a plan that doesn't exist --- app/controllers/search_controller.rb | 2 +- app/services/subscription_service.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index c361c667..56ede4eb 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -25,7 +25,7 @@ class SearchController < ApplicationController # Returns all attributes on a class that we match against in a search. # Usage: searchable_attributes_for(Character) => [:name, :role, ...] def searchable_attributes_for klass - related_controller = "#{klass.to_s.pluralize}Controller".constantize.new + related_controller = "#{klass.to_s.pluralize}Controller".constantize.new # can throw NameError related_controller.send(:content_param_list).select do |attribute| !attribute.is_a?(Hash) && searchable_attribute?(attribute.to_s) end diff --git a/app/services/subscription_service.rb b/app/services/subscription_service.rb index b3da8ce0..e976c0e9 100644 --- a/app/services/subscription_service.rb +++ b/app/services/subscription_service.rb @@ -3,6 +3,7 @@ class SubscriptionService < Service def self.add_subscription(user, plan_id) related_plan = BillingPlan.find_by(stripe_plan_id: plan_id, available: true) + raise "Plan #{plan_id} not available for user #{user.id}" if related_plan.nil? # Add any bonus bandwidth granted by the plan user.update( From 54d773988cedc1d895290b9ac565c8f61da479a1 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 18 Oct 2018 12:49:22 -0500 Subject: [PATCH 22/24] only move users to a new plan when one is provided --- app/controllers/subscriptions_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index 17631c73..6bf5b573 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -82,7 +82,7 @@ class SubscriptionsController < ApplicationController end new_plan_id = params[:plan] - result = move_user_to_plan_requested(new_plan_id) + result = move_user_to_plan_requested(new_plan_id) if new_plan_id if result == :payment_method_needed redirect_to payment_info_path(plan: new_plan_id) From 9cc5eb943eb300c0890ada0dd1b0c07b5ccaad57 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 18 Oct 2018 13:06:38 -0500 Subject: [PATCH 23/24] Require login to view recently-deleted and attributes controller actions --- app/controllers/content_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index ccc35e73..2713217a 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -1,6 +1,6 @@ class ContentController < ApplicationController # todo before_action :load_content to set @content - before_action :authenticate_user!, only: [:index, :new, :create, :edit, :update, :destroy] + before_action :authenticate_user!, only: [:index, :new, :create, :edit, :update, :destroy, :deleted, :attributes] before_action :migrate_old_style_field_values, only: [:show, :edit] before_action :populate_linkable_content_for_each_content_type, only: [:new, :edit] From 5162f72e36f4b8f9e7f6fd81b67f16e833cd50a1 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 18 Oct 2018 13:09:35 -0500 Subject: [PATCH 24/24] upgrade rubyzip to 1.2.2 --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index ef4f0e1e..758790bd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -394,7 +394,7 @@ GEM ruby-prof (0.15.9) ruby-progressbar (1.9.0) ruby_dep (1.5.0) - rubyzip (1.2.1) + rubyzip (1.2.2) safe_yaml (1.0.4) sanitize (4.6.5) crass (~> 1.0.2)