From 71d702b9f0338b6f7b48a3bd6d1cdd91aac8f796 Mon Sep 17 00:00:00 2001 From: Mator Date: Sat, 21 Jan 2017 11:54:25 -0800 Subject: [PATCH 01/17] batch mod search is now game specific --- .../assets/javascripts/BackendAPI/modService.js | 5 ++++- mod-picker/app/controllers/mods_controller.rb | 2 +- mod-picker/app/models/mod.rb | 17 +++++++++-------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/mod-picker/app/assets/javascripts/BackendAPI/modService.js b/mod-picker/app/assets/javascripts/BackendAPI/modService.js index 0753ef48c..c1122e646 100644 --- a/mod-picker/app/assets/javascripts/BackendAPI/modService.js +++ b/mod-picker/app/assets/javascripts/BackendAPI/modService.js @@ -60,7 +60,10 @@ app.service('modService', function(backend, $q, pageUtils, objectUtils, contribu }; this.searchModsBatch = function(batch) { - return backend.post('/mods/search', { batch: batch }); + return backend.post('/mods/search', { + batch: batch, + game: window._current_game_id + }); }; this.retrieveMod = function(modId) { diff --git a/mod-picker/app/controllers/mods_controller.rb b/mod-picker/app/controllers/mods_controller.rb index e4752a3ae..848007e35 100644 --- a/mod-picker/app/controllers/mods_controller.rb +++ b/mod-picker/app/controllers/mods_controller.rb @@ -16,7 +16,7 @@ def index # POST /mods/search def search if params.has_key?(:batch) - @mods = Mod.find_batch(params[:batch]) + @mods = Mod.find_batch(params[:batch], params[:game]) render json: @mods else @mods = Mod.visible.filter(search_params).limit(10) diff --git a/mod-picker/app/models/mod.rb b/mod-picker/app/models/mod.rb index 96bc0a4f1..6be0f99ca 100644 --- a/mod-picker/app/models/mod.rb +++ b/mod-picker/app/models/mod.rb @@ -174,19 +174,20 @@ class Mod < ActiveRecord::Base before_create :set_id before_save :touch_updated - def self.find_by_mod_name(mod_name) - Mod.visible.search(mod_name).first || - Mod.visible.source_mod_name(mod_name, NexusInfo).first || - Mod.visible.source_mod_name(mod_name, LoverInfo).first || - Mod.visible.source_mod_name(mod_name, WorkshopInfo).first + def self.find_by_mod_name(mod_name, game) + base_query = Mod.visible.game(game) + base_query.search(mod_name).first || + base_query.source_mod_name(mod_name, NexusInfo).first || + base_query.source_mod_name(mod_name, LoverInfo).first || + base_query.source_mod_name(mod_name, WorkshopInfo).first end - def self.find_batch(batch) + def self.find_batch(batch, game) batch.collect do |item| if item.has_key?(:nexus_info_id) - Mod.visible.nexus_id(item[:nexus_info_id]).first + Mod.visible.game(game).nexus_id(item[:nexus_info_id]).first else - Mod.find_by_mod_name(item[:mod_name]) + Mod.find_by_mod_name(item[:mod_name], game) end end end From 0484f8da3edbeab6be525f9a643e330a76c0c70e Mon Sep 17 00:00:00 2001 From: Mator Date: Sat, 21 Jan 2017 11:54:40 -0800 Subject: [PATCH 02/17] mod list mod/tool searches are now game specific --- .../app/assets/javascripts/BackendAPI/modService.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mod-picker/app/assets/javascripts/BackendAPI/modService.js b/mod-picker/app/assets/javascripts/BackendAPI/modService.js index c1122e646..d51915ce3 100644 --- a/mod-picker/app/assets/javascripts/BackendAPI/modService.js +++ b/mod-picker/app/assets/javascripts/BackendAPI/modService.js @@ -38,12 +38,13 @@ app.service('modService', function(backend, $q, pageUtils, objectUtils, contribu return backend.post('/mod_options/search', postData); }; - this.searchModListMods = function(name) { + this.searchModListMods = function(str) { var postData = { filters: { - search: name, + search: str, include_games: true, - utility: false + utility: false, + game: window._current_game_id } }; return backend.post('/mods/search', postData); @@ -53,7 +54,8 @@ app.service('modService', function(backend, $q, pageUtils, objectUtils, contribu var postData = { filters: { search: str, - utility: true + utility: true, + game: window._current_game_id } }; return backend.post('/mods/search', postData); From 54b3011607e7d3c431129ada170472fd5d19db9b Mon Sep 17 00:00:00 2001 From: Mator Date: Sat, 21 Jan 2017 11:55:13 -0800 Subject: [PATCH 03/17] plugin search is now game specific --- mod-picker/app/assets/javascripts/BackendAPI/pluginService.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mod-picker/app/assets/javascripts/BackendAPI/pluginService.js b/mod-picker/app/assets/javascripts/BackendAPI/pluginService.js index 03ffa4a90..ed0c845ce 100644 --- a/mod-picker/app/assets/javascripts/BackendAPI/pluginService.js +++ b/mod-picker/app/assets/javascripts/BackendAPI/pluginService.js @@ -33,7 +33,8 @@ app.service('pluginService', function(backend, $q, $timeout, recordGroupService, var plugins = $q.defer(); var postData = { filters: { - search: filename + search: filename, + game: window._current_game_id } }; if (angular.isDefined(modIds)) { From 4480f84c69e35db4e5a96c66f8a1e611b49222c0 Mon Sep 17 00:00:00 2001 From: Mator Date: Sat, 21 Jan 2017 11:55:26 -0800 Subject: [PATCH 04/17] batch plugin search is now game specific --- .../app/assets/javascripts/BackendAPI/pluginService.js | 5 ++++- mod-picker/app/controllers/plugins_controller.rb | 2 +- mod-picker/app/models/plugin.rb | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mod-picker/app/assets/javascripts/BackendAPI/pluginService.js b/mod-picker/app/assets/javascripts/BackendAPI/pluginService.js index ed0c845ce..9e276cc74 100644 --- a/mod-picker/app/assets/javascripts/BackendAPI/pluginService.js +++ b/mod-picker/app/assets/javascripts/BackendAPI/pluginService.js @@ -58,7 +58,10 @@ app.service('pluginService', function(backend, $q, $timeout, recordGroupService, }; this.searchPluginsBatch = function(batch) { - return backend.post('/plugins/search', { batch: batch }); + return backend.post('/plugins/search', { + batch: batch, + game: window._current_game_id + }); }; //combine dummy_masters array with masters array and sorts the masters array diff --git a/mod-picker/app/controllers/plugins_controller.rb b/mod-picker/app/controllers/plugins_controller.rb index 23998ebe3..35e6b8b5f 100644 --- a/mod-picker/app/controllers/plugins_controller.rb +++ b/mod-picker/app/controllers/plugins_controller.rb @@ -16,7 +16,7 @@ def index # POST /plugins/search def search if params.has_key?(:batch) - @plugins = Plugin.find_batch(params[:batch]) + @plugins = Plugin.find_batch(params[:batch], params[:game]) respond_with_json(@plugins, :base) else @plugins = Plugin.visible.filter(search_params).limit(10) diff --git a/mod-picker/app/models/plugin.rb b/mod-picker/app/models/plugin.rb index 2991b1dcf..6603acea6 100644 --- a/mod-picker/app/models/plugin.rb +++ b/mod-picker/app/models/plugin.rb @@ -71,9 +71,9 @@ class Plugin < ActiveRecord::Base before_update :clear_associations before_destroy :prepare_to_destroy - def self.find_batch(batch) + def self.find_batch(batch, game) batch.collect do |item| - Plugin.visible.where(filename: item[:plugin_filename]).first + Plugin.visible.game(game).where(filename: item[:plugin_filename]).first end end From ceac40c262df78a79a6902a5751fabd773a4be1e Mon Sep 17 00:00:00 2001 From: Mator Date: Mon, 23 Jan 2017 12:32:09 -0800 Subject: [PATCH 05/17] curator requests index is now game-specific --- .../app/assets/javascripts/Views/browse/curatorRequests.js | 1 + mod-picker/app/controllers/curator_requests_controller.rb | 2 +- mod-picker/app/models/curator_request.rb | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mod-picker/app/assets/javascripts/Views/browse/curatorRequests.js b/mod-picker/app/assets/javascripts/Views/browse/curatorRequests.js index 82d28e798..5aa5755f9 100644 --- a/mod-picker/app/assets/javascripts/Views/browse/curatorRequests.js +++ b/mod-picker/app/assets/javascripts/Views/browse/curatorRequests.js @@ -22,6 +22,7 @@ app.controller('curatorRequestsIndexController', function($scope, $rootScope, $s // filters for view $scope.filterPrototypes = filtersFactory.curatorRequestFilters(); $scope.dateFilters = filtersFactory.curatorRequestDateFilters(); + $scope.filters = { game: $scope.currentGame.id }; // build generic controller stuff $scope.route = 'curator_requests'; diff --git a/mod-picker/app/controllers/curator_requests_controller.rb b/mod-picker/app/controllers/curator_requests_controller.rb index b091374c0..dd4293498 100644 --- a/mod-picker/app/controllers/curator_requests_controller.rb +++ b/mod-picker/app/controllers/curator_requests_controller.rb @@ -56,7 +56,7 @@ def sorting_params # Params we allow filtering on def filtering_params - params[:filters].slice(:search, :submitter, :mod_name, :state, :submitted, :updated) + params[:filters].slice(:game, :search, :submitter, :mod_name, :state, :submitted, :updated) end end diff --git a/mod-picker/app/models/curator_request.rb b/mod-picker/app/models/curator_request.rb index 6cd83341d..e680455af 100644 --- a/mod-picker/app/models/curator_request.rb +++ b/mod-picker/app/models/curator_request.rb @@ -15,6 +15,7 @@ class CuratorRequest < ActiveRecord::Base # UNIQUE SCOPES scope :mod_name, -> (name) { where("mods.name LIKE ?", "%#{name}%") } + scope :game, -> (game_id) { where("mods.game_id = ?", game_id) } # ASSOCIATIONS belongs_to :submitter, :class_name => 'User', :foreign_key => 'submitted_by', :inverse_of => 'curator_requests' From a759e8e44995b7a237fb563216cc0dfd5fa4d4ff Mon Sep 17 00:00:00 2001 From: Mator Date: Mon, 23 Jan 2017 12:32:27 -0800 Subject: [PATCH 06/17] moderation cp now displays game-specific counts --- .../javascripts/BackendAPI/moderationService.js | 4 +++- mod-picker/app/controllers/moderation_controller.rb | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/mod-picker/app/assets/javascripts/BackendAPI/moderationService.js b/mod-picker/app/assets/javascripts/BackendAPI/moderationService.js index 78be3999b..c73e1ac3b 100644 --- a/mod-picker/app/assets/javascripts/BackendAPI/moderationService.js +++ b/mod-picker/app/assets/javascripts/BackendAPI/moderationService.js @@ -1,5 +1,7 @@ app.service('moderationService', function(backend) { this.retrieveStats = function() { - return backend.retrieve("/moderator_cp"); + return backend.retrieve("/moderator_cp", { + game: window._current_game_id + }); }; }); diff --git a/mod-picker/app/controllers/moderation_controller.rb b/mod-picker/app/controllers/moderation_controller.rb index 40ff4c562..d2a06483e 100644 --- a/mod-picker/app/controllers/moderation_controller.rb +++ b/mod-picker/app/controllers/moderation_controller.rb @@ -4,12 +4,12 @@ def index raise AccessDenied("You must be a moderator to access this resource.") unless current_user.can_moderate? render json: { unapproved: { - curator_requests: CuratorRequest.unapproved_count, - reviews: Review.unapproved_count, - compatibility_notes: CompatibilityNote.unapproved_count, - install_order_notes: InstallOrderNote.unapproved_count, - load_order_notes: LoadOrderNote.unapproved_count, - mods: Mod.unapproved_count, + curator_requests: CuratorRequest.eager_load(:mod).game(params[:game]).unapproved_count, + reviews: Review.game(params[:game]).unapproved_count, + compatibility_notes: CompatibilityNote.game(params[:game]).unapproved_count, + install_order_notes: InstallOrderNote.game(params[:game]).unapproved_count, + load_order_notes: LoadOrderNote.game(params[:game]).unapproved_count, + mods: Mod.game(params[:game]).unapproved_count, help_pages: HelpPage.unapproved_count }, unresolved_reports: BaseReport.unresolved_count From 73d5d93a60197c4cd2b81a5f4f3abe124a00be1f Mon Sep 17 00:00:00 2001 From: Mator Date: Mon, 23 Jan 2017 13:34:47 -0800 Subject: [PATCH 07/17] created active mod list model --- mod-picker/app/models/active_mod_list.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 mod-picker/app/models/active_mod_list.rb diff --git a/mod-picker/app/models/active_mod_list.rb b/mod-picker/app/models/active_mod_list.rb new file mode 100644 index 000000000..6748350dd --- /dev/null +++ b/mod-picker/app/models/active_mod_list.rb @@ -0,0 +1,17 @@ +class ActiveModList < ActiveRecord::Base + include BetterJson + + belongs_to :game + belongs_to :user + belongs_to :mod_list + + def self.apply(game, user, mod_list) + if mod_list.present? + ActiveModList.create(game_id: game, user_id: user.id, mod_list_id: mod_list.id) + end + end + + def self.clear(game, user) + ActiveModList.where(user_id: user.id, game_id: game).delete_all + end +end From eb8aefd053e991cd4b681cc49d190bb644b1d7a0 Mon Sep 17 00:00:00 2001 From: Mator Date: Mon, 23 Jan 2017 13:35:44 -0800 Subject: [PATCH 08/17] created and ran migration to create active_mod_lists table --- .../20170121195705_create_active_mod_lists.rb | 27 +++++++++++++++++++ mod-picker/db/schema.rb | 18 ++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 mod-picker/db/migrate/20170121195705_create_active_mod_lists.rb diff --git a/mod-picker/db/migrate/20170121195705_create_active_mod_lists.rb b/mod-picker/db/migrate/20170121195705_create_active_mod_lists.rb new file mode 100644 index 000000000..c7d15c556 --- /dev/null +++ b/mod-picker/db/migrate/20170121195705_create_active_mod_lists.rb @@ -0,0 +1,27 @@ +class CreateActiveModLists < ActiveRecord::Migration + def change + create_table :active_mod_lists do |t| + t.integer :game_id, null: false + t.integer :user_id, null: false + t.integer :mod_list_id, null: false + end + + add_foreign_key :active_mod_lists, :games + add_foreign_key :active_mod_lists, :users + add_foreign_key :active_mod_lists, :mod_lists + add_index :active_mod_lists, [:game_id, :user_id, :mod_list_id], unique: true + + User.find_each do |user| + next unless user.active_mod_list_id + puts "User #{user.id}, active mod list: #{user.active_mod_list_id}" + ActiveModList.create({ + game_id: user.active_mod_list.game_id, + user_id: user.id, + mod_list_id: user.active_mod_list_id + }) + end + + remove_foreign_key :users, column: "active_mod_list_id" + remove_column :users, :active_mod_list_id + end +end diff --git a/mod-picker/db/schema.rb b/mod-picker/db/schema.rb index 01b8a7275..49fff8417 100644 --- a/mod-picker/db/schema.rb +++ b/mod-picker/db/schema.rb @@ -11,7 +11,17 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170119210115) do +ActiveRecord::Schema.define(version: 20170121195705) do + + create_table "active_mod_lists", force: :cascade do |t| + t.integer "game_id", limit: 4, null: false + t.integer "user_id", limit: 4, null: false + t.integer "mod_list_id", limit: 4, null: false + end + + add_index "active_mod_lists", ["game_id", "user_id", "mod_list_id"], name: "index_active_mod_lists_on_game_id_and_user_id_and_mod_list_id", unique: true, using: :btree + add_index "active_mod_lists", ["mod_list_id"], name: "fk_rails_0659fed997", using: :btree + add_index "active_mod_lists", ["user_id"], name: "fk_rails_c1d0166a09", using: :btree create_table "agreement_marks", id: false, force: :cascade do |t| t.integer "correction_id", limit: 4, null: false @@ -929,7 +939,6 @@ t.string "email", limit: 255, default: "", null: false t.string "role", limit: 16, null: false t.string "title", limit: 32 - t.integer "active_mod_list_id", limit: 4 t.text "about_me", limit: 65535 t.integer "comments_count", limit: 4, default: 0, null: false t.integer "authored_mods_count", limit: 4, default: 0, null: false @@ -973,7 +982,6 @@ t.integer "invitations_count", limit: 4, default: 0 end - add_index "users", ["active_mod_list_id"], name: "active_ml_id", using: :btree add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index "users", ["invitation_token"], name: "index_users_on_invitation_token", unique: true, using: :btree @@ -1002,6 +1010,9 @@ add_index "workshop_infos", ["mod_id"], name: "fk_rails_8707144ad7", using: :btree + add_foreign_key "active_mod_lists", "games" + add_foreign_key "active_mod_lists", "mod_lists" + add_foreign_key "active_mod_lists", "users" add_foreign_key "agreement_marks", "corrections" add_foreign_key "agreement_marks", "users", column: "submitted_by", name: "agreement_marks_ibfk_2" add_foreign_key "api_tokens", "users" @@ -1128,6 +1139,5 @@ add_foreign_key "user_reputations", "users", name: "user_reputations_ibfk_1" add_foreign_key "user_settings", "users", name: "user_settings_ibfk_1" add_foreign_key "user_titles", "games" - add_foreign_key "users", "mod_lists", column: "active_mod_list_id", name: "users_ibfk_4" add_foreign_key "workshop_infos", "mods" end From 5914f16b27a87f5fc5702d7da14f550959e29a81 Mon Sep 17 00:00:00 2001 From: Mator Date: Mon, 23 Jan 2017 13:38:02 -0800 Subject: [PATCH 09/17] updated associations for active mod lists --- mod-picker/app/models/active_mod_list.rb | 2 +- mod-picker/app/models/user.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/mod-picker/app/models/active_mod_list.rb b/mod-picker/app/models/active_mod_list.rb index 6748350dd..a2933551e 100644 --- a/mod-picker/app/models/active_mod_list.rb +++ b/mod-picker/app/models/active_mod_list.rb @@ -2,7 +2,7 @@ class ActiveModList < ActiveRecord::Base include BetterJson belongs_to :game - belongs_to :user + belongs_to :user, inverse_of: 'active_mod_lists' belongs_to :mod_list def self.apply(game, user, mod_list) diff --git a/mod-picker/app/models/user.rb b/mod-picker/app/models/user.rb index fb3f85802..1d5f840c2 100644 --- a/mod-picker/app/models/user.rb +++ b/mod-picker/app/models/user.rb @@ -62,8 +62,7 @@ class User < ActiveRecord::Base has_many :mod_authors, :inverse_of => 'user' has_many :mods, :through => 'mod_authors', :inverse_of => 'author_users' has_many :mod_lists, :foreign_key => 'submitted_by', :inverse_of => 'submitter' - - belongs_to :active_mod_list, :class_name => 'ModList', :foreign_key => 'active_mod_list_id' + has_many :active_mod_lists, :inverse_of => 'user' has_many :mod_stars, :inverse_of => 'user' has_many :starred_mods, :class_name => 'Mod', :through => 'mod_stars', :source => 'mod', :inverse_of => 'user_stars' From e0160c73296cd7f575571742836270ef3a76cd09 Mon Sep 17 00:00:00 2001 From: Mator Date: Mon, 23 Jan 2017 15:03:24 -0800 Subject: [PATCH 10/17] updated models for active mod list tracking --- mod-picker/app/models/active_mod_list.rb | 6 +++++- mod-picker/app/models/mod_list.rb | 4 ++-- mod-picker/app/models/user.rb | 5 +++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/mod-picker/app/models/active_mod_list.rb b/mod-picker/app/models/active_mod_list.rb index a2933551e..28932d143 100644 --- a/mod-picker/app/models/active_mod_list.rb +++ b/mod-picker/app/models/active_mod_list.rb @@ -1,6 +1,10 @@ class ActiveModList < ActiveRecord::Base - include BetterJson + include ScopeHelpers, BetterJson + # SCOPES + game_scope + + # ASSOCIATIONS belongs_to :game belongs_to :user, inverse_of: 'active_mod_lists' belongs_to :mod_list diff --git a/mod-picker/app/models/mod_list.rb b/mod-picker/app/models/mod_list.rb index 34972b377..742259f7e 100644 --- a/mod-picker/app/models/mod_list.rb +++ b/mod-picker/app/models/mod_list.rb @@ -224,8 +224,8 @@ def self.update_adult(ids) end def set_active - submitter.active_mod_list_id = id - submitter.save + ActiveModList.clear(game_id, submitted_by) + ActiveModList.create(game_id: game_id, user_id: submitted_by, mod_list_id: id) end def mod_list_plugin_ids diff --git a/mod-picker/app/models/user.rb b/mod-picker/app/models/user.rb index 1d5f840c2..7fd90b48e 100644 --- a/mod-picker/app/models/user.rb +++ b/mod-picker/app/models/user.rb @@ -109,6 +109,11 @@ def recent_notifications notifications.unread.limit(10) end + def active_mod_list(game) + a = active_mod_lists.game(game).first + a && a.mod_list + end + def admin? role.to_sym == :admin end From 9585b3ab47ac968951cab4e17eaa4cb89d275ea2 Mon Sep 17 00:00:00 2001 From: Mator Date: Mon, 23 Jan 2017 15:04:33 -0800 Subject: [PATCH 11/17] updated active mod list controller/service/view logic - all working now --- .../javascripts/BackendAPI/modListService.js | 18 ++++++-- .../javascripts/BackendAPI/userService.js | 4 ++ .../app/controllers/mod_lists_controller.rb | 46 +++++++++++++------ mod-picker/app/views/users/current.json | 3 ++ mod-picker/app/views/users/index.json | 2 +- mod-picker/app/views/users/settings.json | 5 +- mod-picker/app/views/users/show.json | 2 +- 7 files changed, 58 insertions(+), 22 deletions(-) diff --git a/mod-picker/app/assets/javascripts/BackendAPI/modListService.js b/mod-picker/app/assets/javascripts/BackendAPI/modListService.js index 990e09761..6e54786cf 100644 --- a/mod-picker/app/assets/javascripts/BackendAPI/modListService.js +++ b/mod-picker/app/assets/javascripts/BackendAPI/modListService.js @@ -19,7 +19,9 @@ app.service('modListService', function(backend, $q, userTitleService, contributi this.retrieveActiveModList = function() { var action = $q.defer(); - backend.retrieve('/mod_lists/active').then(function(data) { + backend.retrieve('/mod_lists/active', { + game: window._current_game_id + }).then(function(data) { if (data.error) { action.resolve(null); } @@ -31,7 +33,10 @@ app.service('modListService', function(backend, $q, userTitleService, contributi }; this.setActiveModList = function(modListId) { - return backend.post('/mod_lists/active', {id: modListId}); + return backend.post('/mod_lists/active', { + id: modListId, + game: window._current_game_id + }); }; this.starModList = function(modListId, starred) { @@ -174,7 +179,10 @@ app.service('modListService', function(backend, $q, userTitleService, contributi }; this.newModList = function(mod_list, active) { - return backend.post('/mod_lists', {mod_list: mod_list, active: active}) + return backend.post('/mod_lists', { + mod_list: mod_list, + active: active + }); }; this.newModListMod = function(mod_list_mod) { @@ -287,7 +295,9 @@ app.service('modListService', function(backend, $q, userTitleService, contributi }; this.addModCollection = function(modListId) { - return backend.post('/mod_lists/' + modListId + '/add', {}); + return backend.post('/mod_lists/' + modListId + '/add', { + game: window._current_game_id + }); }; this.hideModList = function(modListId, hidden) { diff --git a/mod-picker/app/assets/javascripts/BackendAPI/userService.js b/mod-picker/app/assets/javascripts/BackendAPI/userService.js index 85bf8b541..ac63890b1 100644 --- a/mod-picker/app/assets/javascripts/BackendAPI/userService.js +++ b/mod-picker/app/assets/javascripts/BackendAPI/userService.js @@ -38,6 +38,10 @@ app.service('userService', function(backend, $q, userSettingsService, userTitleS if (userData) { userData.signed_in = true; userData.permissions = service.getPermissions(userData); + var activeModList = userData.active_mod_lists.find(function(item) { + return item.game_id == window._current_game_id; + }); + userData.active_mod_list_id = activeModList && activeModList.mod_list_id; } else { userData = { permissions: {} }; } diff --git a/mod-picker/app/controllers/mod_lists_controller.rb b/mod-picker/app/controllers/mod_lists_controller.rb index 984da48f6..bfbaae38f 100644 --- a/mod-picker/app/controllers/mod_lists_controller.rb +++ b/mod-picker/app/controllers/mod_lists_controller.rb @@ -1,6 +1,7 @@ class ModListsController < ApplicationController before_action :check_sign_in, only: [:create, :set_active, :update, :import, :update_tags, :create_star, :destroy_star] before_action :set_mod_list, only: [:show, :hide, :clone, :add, :update, :import, :update_tags, :tools, :mods, :plugins, :export_modlist, :export_plugins, :export_links, :config_files, :analysis, :comments] + before_action :soft_set_mod_list, only: [:set_active] # GET /mod_lists def index @@ -26,7 +27,7 @@ def show # GET /mod_lists/active def active - @mod_list = current_user.present? && current_user.active_mod_list + @mod_list = current_user && current_user.active_mod_list(params[:game]) if @mod_list respond_with_json(@mod_list, :tracking) else @@ -221,7 +222,7 @@ def clone # POST /mod_lists/1/add def add authorize! :read, @mod_list - @target_mod_list = current_user.active_mod_list + @target_mod_list = current_user.active_mod_list(params[:game]) builder = ModListBuilder.new(@mod_list, @target_mod_list) builder.copy! respond_with_json(@target_mod_list, :tracking, :mod_list) @@ -229,17 +230,16 @@ def add # POST /mod_lists/active def set_active - @mod_list = nil - if params.has_key?(:id) && params[:id] - @mod_list = ModList.find(params[:id]) - authorize! :read, @mod_list - end - - if current_user.update(active_mod_list_id: params[:id]) - render json: { mod_list: nil } unless @mod_list.present? - respond_with_json(@mod_list, :tracking, :mod_list) + ActiveModList.clear(params[:game], current_user) + if @mod_list.present? + @active_mod_list = ActiveModList.new(active_mod_list_params) + if @active_mod_list.save + respond_with_json(@mod_list, :tracking, :mod_list) + else + render json: @active_mod_list.errors, status: :unproccessable_entity + end else - render json: current_user.errors, status: :unproccessable_entity + render json: { mod_list: nil } end end @@ -322,6 +322,14 @@ def set_mod_list @mod_list = ModList.find(params[:id]) end + def soft_set_mod_list + @mod_list = nil + if params.has_key?(:id) && params[:id] + @mod_list = ModList.find(params[:id]) + authorize! :read, @mod_list + end + end + def force_download(filename) response.headers["Content-Disposition"] = "attachment; filename=#{filename}" end @@ -356,7 +364,15 @@ def mod_list_params ) end - def mod_list_import_params - params.permit(mods: [:id, :name, :nexus_info_id], plugins: [:id, :filename]) - end + def mod_list_import_params + params.permit(mods: [:id, :name, :nexus_info_id], plugins: [:id, :filename]) + end + + def active_mod_list_params + { + game_id: params[:game], + user_id: current_user.id, + mod_list_id: params[:id] + } + end end diff --git a/mod-picker/app/views/users/current.json b/mod-picker/app/views/users/current.json index 3ec8b920a..d3526bd11 100644 --- a/mod-picker/app/views/users/current.json +++ b/mod-picker/app/views/users/current.json @@ -6,6 +6,9 @@ }, "settings": { "only": ["skyrim_theme", "skyrimse_theme", "enable_spellcheck", "show_notifications", "allow_adult_content", "disable_helper"] + }, + "active_mod_lists": { + "only": ["game_id", "mod_list_id"] } }, "methods": ["image_type", "recent_notifications"] diff --git a/mod-picker/app/views/users/index.json b/mod-picker/app/views/users/index.json index 0d631222b..6d8846232 100644 --- a/mod-picker/app/views/users/index.json +++ b/mod-picker/app/views/users/index.json @@ -1,5 +1,5 @@ { - "except": ["about_me", "active_mod_list_id", "invitation_token", "invitation_created_at", "invitation_sent_at", "invitation_accepted_at", "invitation_limit", "invited_by_id", "invited_by_type", "invitations_count"], + "except": ["about_me", "invitation_token", "invitation_created_at", "invitation_sent_at", "invitation_accepted_at", "invitation_limit", "invited_by_id", "invited_by_type", "invitations_count"], "methods": ["image_type", "last_sign_in_at", "current_sign_in_at"], "include": { "reputation": {} diff --git a/mod-picker/app/views/users/settings.json b/mod-picker/app/views/users/settings.json index a77bf5611..951538c90 100644 --- a/mod-picker/app/views/users/settings.json +++ b/mod-picker/app/views/users/settings.json @@ -1,5 +1,5 @@ { - "except": ["active_mod_list_id", "invitation_token", "invitation_created_at", "invitation_sent_at", "invitation_accepted_at", "invitation_limit", "invited_by_id", "invited_by_type", "invitations_count"], + "except": ["invitation_token", "invitation_created_at", "invitation_sent_at", "invitation_accepted_at", "invitation_limit", "invited_by_id", "invited_by_type", "invitations_count"], "include": { "bio": { "except": ["user_id"] @@ -9,6 +9,9 @@ }, "settings": { "except": ["user_id", "fallout4_theme", "oblivion_theme", "falloutnv_theme", "fallout3_theme"] + }, + "active_mod_lists": { + "only": ["game_id", "mod_list_id"] } }, "methods": "image_type" diff --git a/mod-picker/app/views/users/show.json b/mod-picker/app/views/users/show.json index 55c755b1c..3c5bf3e8f 100644 --- a/mod-picker/app/views/users/show.json +++ b/mod-picker/app/views/users/show.json @@ -1,5 +1,5 @@ { - "except": ["email", "active_mod_list_id", "invitation_token", "invitation_created_at", "invitation_sent_at", "invitation_accepted_at", "invitation_limit", "invited_by_id", "invited_by_type", "invitations_count"], + "except": ["email", "invitation_token", "invitation_created_at", "invitation_sent_at", "invitation_accepted_at", "invitation_limit", "invited_by_id", "invited_by_type", "invitations_count"], "include": { "bio": { "except": ["user_id", "nexus_verification_token", "lover_verification_token", "workshop_verification_token"] From 3c17ab83a73a1b588239d8316ed856e182051dba Mon Sep 17 00:00:00 2001 From: Mator Date: Mon, 23 Jan 2017 15:04:49 -0800 Subject: [PATCH 12/17] user settings and user profile mods/mod lists are now game specific --- .../app/assets/javascripts/BackendAPI/userService.js | 12 +++++++++--- .../Views/userSettings/userSettingsModLists.js | 1 + .../Views/userSettings/userSettingsMods.js | 1 + mod-picker/app/controllers/users_controller.rb | 9 ++++----- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/mod-picker/app/assets/javascripts/BackendAPI/userService.js b/mod-picker/app/assets/javascripts/BackendAPI/userService.js index ac63890b1..2262bdb6b 100644 --- a/mod-picker/app/assets/javascripts/BackendAPI/userService.js +++ b/mod-picker/app/assets/javascripts/BackendAPI/userService.js @@ -106,14 +106,20 @@ app.service('userService', function(backend, $q, userSettingsService, userTitleS }; this.changeRole = function(userId, role) { - return backend.post('/users/' + userId + '/change_role', {role: role}); + return backend.post('/users/' + userId + '/change_role', { + role: role + }); }; this.retrieveUserModLists = function(userId) { - return backend.retrieve('/users/' + userId + '/mod_lists'); + return backend.retrieve('/users/' + userId + '/mod_lists', { + game: window._current_game_id + }); }; this.retrieveUserMods = function(userId) { - return backend.retrieve('/users/' + userId + '/mods'); + return backend.retrieve('/users/' + userId + '/mods', { + game: window._current_game_id + }); }; }); diff --git a/mod-picker/app/assets/javascripts/Views/userSettings/userSettingsModLists.js b/mod-picker/app/assets/javascripts/Views/userSettings/userSettingsModLists.js index 3f6ffd721..15a0b45dc 100644 --- a/mod-picker/app/assets/javascripts/Views/userSettings/userSettingsModLists.js +++ b/mod-picker/app/assets/javascripts/Views/userSettings/userSettingsModLists.js @@ -14,6 +14,7 @@ app.controller('userSettingsModListsController', function($scope, $rootScope, $t $scope.retrieveModLists = function() { var options = { filters: { + game: window._current_game_id, submitter: $scope.user.username } }; diff --git a/mod-picker/app/assets/javascripts/Views/userSettings/userSettingsMods.js b/mod-picker/app/assets/javascripts/Views/userSettings/userSettingsMods.js index 2a8cf03b8..31fef762a 100644 --- a/mod-picker/app/assets/javascripts/Views/userSettings/userSettingsMods.js +++ b/mod-picker/app/assets/javascripts/Views/userSettings/userSettingsMods.js @@ -8,6 +8,7 @@ app.controller('userSettingsModsController', function($scope, columnsFactory, ac $scope.retrieveMods = function() { var options = { filters: { + game: window._current_game_id, mp_author: $scope.user.username, sources: { nexus: true, diff --git a/mod-picker/app/controllers/users_controller.rb b/mod-picker/app/controllers/users_controller.rb index 5662577fd..e96f679e2 100644 --- a/mod-picker/app/controllers/users_controller.rb +++ b/mod-picker/app/controllers/users_controller.rb @@ -115,8 +115,8 @@ def change_role def mod_lists authorize! :read, @user - favorite_mod_lists = @user.starred_mod_lists.accessible_by(current_ability) - authored_mod_lists = @user.mod_lists.accessible_by(current_ability) + favorite_mod_lists = @user.starred_mod_lists.game(params[:game]).accessible_by(current_ability) + authored_mod_lists = @user.mod_lists.game(params[:game]).accessible_by(current_ability) render json: { favorites: favorite_mod_lists, @@ -134,9 +134,8 @@ def api_tokens def mods authorize! :read, @user - favorite_mods = @user.starred_mods.includes(:author_users).accessible_by(current_ability) - authored_mods = @user.mods.includes(:author_users).accessible_by(current_ability) - sources = { nexus: true, lab: true, workshop: true } + favorite_mods = @user.starred_mods.game(params[:game]).includes(:author_users).accessible_by(current_ability) + authored_mods = @user.mods.game(params[:game]).includes(:author_users).accessible_by(current_ability) render json: { favorites: json_format(favorite_mods, :index), From 661db6062200520b46a2ea8a8cbc04e1cfe0394a Mon Sep 17 00:00:00 2001 From: Mator Date: Mon, 23 Jan 2017 15:05:17 -0800 Subject: [PATCH 13/17] fixed required plugin links --- .../resources/partials/modList/requiredPlugins.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mod-picker/public/resources/partials/modList/requiredPlugins.html b/mod-picker/public/resources/partials/modList/requiredPlugins.html index f1cf80860..4b9fa1b8e 100644 --- a/mod-picker/public/resources/partials/modList/requiredPlugins.html +++ b/mod-picker/public/resources/partials/modList/requiredPlugins.html @@ -13,10 +13,10 @@
  • - {{requirement.master_plugin.filename}} + {{requirement.master_plugin.filename}} is required by - {{plugin.filename}}{{!$last || requirement.plugins.length > 2 ? ', ' : ''}} + {{plugin.filename}}{{!$last || requirement.plugins.length > 2 ? ', ' : ''}} and @@ -35,10 +35,10 @@
    • - {{requirement.master_plugin.filename}} + {{requirement.master_plugin.filename}} is required by - {{plugin.filename}}{{!$last || requirement.plugins.length > 2 ? ', ' : ''}} + {{plugin.filename}}{{!$last || requirement.plugins.length > 2 ? ', ' : ''}} and From aaafb15eb74312b70029f628bfcb1d68f564ec19 Mon Sep 17 00:00:00 2001 From: Mator Date: Mon, 23 Jan 2017 15:28:40 -0800 Subject: [PATCH 14/17] plugin master associations are now constructed in a game-specific fashion --- mod-picker/app/models/plugin.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mod-picker/app/models/plugin.rb b/mod-picker/app/models/plugin.rb index 6603acea6..01c8d6983 100644 --- a/mod-picker/app/models/plugin.rb +++ b/mod-picker/app/models/plugin.rb @@ -77,9 +77,9 @@ def self.find_batch(batch, game) end end - def self.find_master_plugin(master) - Plugin.where(filename: master[:filename], crc_hash: master[:crc_hash]).first || - Plugin.where(filename: master[:filename]).first + def self.find_master_plugin(game, master) + Plugin.game(game).where(filename: master[:filename], crc_hash: master[:crc_hash]).first || + Plugin.game(game).where(filename: master[:filename]).first end def update_lazy_counters @@ -96,7 +96,7 @@ def update_counters def create_associations if @master_plugins @master_plugins.each_with_index do |master, index| - master_plugin = Plugin.find_master_plugin(master) + master_plugin = Plugin.find_master_plugin(game_id, master) if master_plugin.nil? dummy_masters.create(filename: master[:filename], index: index) else From 3011fa3a440e9a68ec7f37c9f6af31622b40a4a3 Mon Sep 17 00:00:00 2001 From: Mator Date: Mon, 23 Jan 2017 16:06:50 -0800 Subject: [PATCH 15/17] mod and mod list retrieval is now game-specific --- .../app/assets/javascripts/BackendAPI/modListService.js | 4 +++- mod-picker/app/assets/javascripts/BackendAPI/modService.js | 4 +++- mod-picker/app/controllers/mod_lists_controller.rb | 3 ++- mod-picker/app/controllers/mods_controller.rb | 6 +++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/mod-picker/app/assets/javascripts/BackendAPI/modListService.js b/mod-picker/app/assets/javascripts/BackendAPI/modListService.js index 6e54786cf..881da30e5 100644 --- a/mod-picker/app/assets/javascripts/BackendAPI/modListService.js +++ b/mod-picker/app/assets/javascripts/BackendAPI/modListService.js @@ -14,7 +14,9 @@ app.service('modListService', function(backend, $q, userTitleService, contributi }; this.retrieveModList = function(modListId) { - return backend.retrieve('/mod_lists/' + modListId); + return backend.retrieve('/mod_lists/' + modListId, { + game: window._current_game_id + }); }; this.retrieveActiveModList = function() { diff --git a/mod-picker/app/assets/javascripts/BackendAPI/modService.js b/mod-picker/app/assets/javascripts/BackendAPI/modService.js index d51915ce3..c400f7e59 100644 --- a/mod-picker/app/assets/javascripts/BackendAPI/modService.js +++ b/mod-picker/app/assets/javascripts/BackendAPI/modService.js @@ -70,7 +70,9 @@ app.service('modService', function(backend, $q, pageUtils, objectUtils, contribu this.retrieveMod = function(modId) { var action = $q.defer(); - backend.retrieve('/mods/' + modId).then(function(data) { + backend.retrieve('/mods/' + modId, { + game: window._current_game_id + }).then(function(data) { service.associateModImage(data.mod); action.resolve(data); }, function(response) { diff --git a/mod-picker/app/controllers/mod_lists_controller.rb b/mod-picker/app/controllers/mod_lists_controller.rb index bfbaae38f..060c2f925 100644 --- a/mod-picker/app/controllers/mod_lists_controller.rb +++ b/mod-picker/app/controllers/mod_lists_controller.rb @@ -1,6 +1,6 @@ class ModListsController < ApplicationController before_action :check_sign_in, only: [:create, :set_active, :update, :import, :update_tags, :create_star, :destroy_star] - before_action :set_mod_list, only: [:show, :hide, :clone, :add, :update, :import, :update_tags, :tools, :mods, :plugins, :export_modlist, :export_plugins, :export_links, :config_files, :analysis, :comments] + before_action :set_mod_list, only: [:hide, :clone, :add, :update, :import, :update_tags, :tools, :mods, :plugins, :export_modlist, :export_plugins, :export_links, :config_files, :analysis, :comments] before_action :soft_set_mod_list, only: [:set_active] # GET /mod_lists @@ -17,6 +17,7 @@ def index # GET /mod_lists/1 def show + @mod_list = ModList.game(params[:game]).find(params[:id]) authorize! :read, @mod_list, message: "You are not allowed to view this mod list." star = current_user.present? && ModListStar.exists?(mod_list_id: @mod_list.id, user_id: current_user.id) render json: { diff --git a/mod-picker/app/controllers/mods_controller.rb b/mod-picker/app/controllers/mods_controller.rb index 848007e35..6fa3399c2 100644 --- a/mod-picker/app/controllers/mods_controller.rb +++ b/mod-picker/app/controllers/mods_controller.rb @@ -26,7 +26,7 @@ def search # GET /mods/1 def show - @mod = Mod.includes(:custom_sources, :plugins, {mod_authors: :user}, {tags: :submitter}, {required_mods: :required_mod}, {required_by: :mod}).find(params[:id]) + @mod = Mod.game(params[:game]).includes(:custom_sources, :plugins, {mod_authors: :user}, {tags: :submitter}, {required_mods: :required_mod}, {required_by: :mod}).find(params[:id]) authorize! :read, @mod, message: "You are not allowed to view this mod." # set up boolean variables @@ -35,8 +35,8 @@ def show incompatible = false if current_user.present? star = ModStar.exists?(mod_id: @mod.id, user_id: current_user.id) - if current_user.active_mod_list_id.present? - mod_list = current_user.active_mod_list + if current_user.active_mod_list(@mod.game_id).present? + mod_list = current_user.active_mod_list(@mod.game_id) in_mod_list = mod_list.mod_list_mod_ids.include?(@mod.id) incompatible = mod_list.incompatible_mod_ids.include?(@mod.id) end From 0a85c665485a5f8b4c7f1ced5ed84521ce3cccd1 Mon Sep 17 00:00:00 2001 From: Mator Date: Mon, 23 Jan 2017 16:17:46 -0800 Subject: [PATCH 16/17] actually fixed issue with required plugin links --- mod-picker/app/models/mod_list.rb | 3 +-- mod-picker/app/views/masters/plugin.json | 5 ++++- mod-picker/app/views/plugins/master.json | 5 ++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/mod-picker/app/models/mod_list.rb b/mod-picker/app/models/mod_list.rb index 742259f7e..3a75dbc38 100644 --- a/mod-picker/app/models/mod_list.rb +++ b/mod-picker/app/models/mod_list.rb @@ -292,8 +292,7 @@ def required_mods def required_plugins plugin_ids = mod_list_plugin_ids return Master.none if plugin_ids.empty? - - Master.plugins(plugin_ids).visible.order(:master_plugin_id) + Master.eager_load(:plugin => :mod, :master_plugin => :mod).plugins(plugin_ids).visible.order(:master_plugin_id) end def incompatible_mod_ids diff --git a/mod-picker/app/views/masters/plugin.json b/mod-picker/app/views/masters/plugin.json index 5df2f8b42..50ba4e897 100644 --- a/mod-picker/app/views/masters/plugin.json +++ b/mod-picker/app/views/masters/plugin.json @@ -2,7 +2,10 @@ "except": ["plugin_id"], "include": { "master_plugin": { - "only": ["id", "mod_id", "filename"] + "only": ["id", "filename"], + "include": { + "mod": {} + } } } } \ No newline at end of file diff --git a/mod-picker/app/views/plugins/master.json b/mod-picker/app/views/plugins/master.json index 3ddd833b4..32cdf3d65 100644 --- a/mod-picker/app/views/plugins/master.json +++ b/mod-picker/app/views/plugins/master.json @@ -1,3 +1,6 @@ { - "only": ["id", "filename", "mod_option_id"] + "only": ["id", "filename", "mod_option_id"], + "include": { + "mod": {} + } } \ No newline at end of file From 8f51861ac7800de856e46bf0db24a96bd8e6724d Mon Sep 17 00:00:00 2001 From: Mator Date: Mon, 23 Jan 2017 16:22:06 -0800 Subject: [PATCH 17/17] fixed bug with moving game plugins in listUtils.getCanInsert --- mod-picker/app/assets/javascripts/Services/listUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod-picker/app/assets/javascripts/Services/listUtils.js b/mod-picker/app/assets/javascripts/Services/listUtils.js index 467c87823..868a88aab 100644 --- a/mod-picker/app/assets/javascripts/Services/listUtils.js +++ b/mod-picker/app/assets/javascripts/Services/listUtils.js @@ -197,7 +197,7 @@ app.service('listUtils', function() { }; this.getCanInsert = function(key, moveItem) { - return key === "plugin" && moveItem.mod.primary_category.name === "Fixes - Patches"; + return key === "plugin" && moveItem.mod.primary_category && moveItem.mod.primary_category.name === "Fixes - Patches"; }; this.moveItem = function(model, key, options) {