From 1220466035286d442e46bc412bbd12dc7697a14d Mon Sep 17 00:00:00 2001 From: zmagod Date: Wed, 25 Jan 2017 15:00:14 +0100 Subject: [PATCH] fixing hound --- app/models/user.rb | 183 +++++++++++++++------ app/utilities/first_time_data_generator.rb | 4 +- app/utilities/protocols_importer.rb | 2 +- config/initializers/assets.rb | 21 ++- config/routes.rb | 2 +- 5 files changed, 149 insertions(+), 63 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index fb428941a..10d340c7e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -52,46 +52,123 @@ class User < ActiveRecord::Base has_many :custom_fields, inverse_of: :user has_many :reports, inverse_of: :user has_many :created_assets, class_name: 'Asset', foreign_key: 'created_by_id' - has_many :modified_assets, class_name: 'Asset', foreign_key: 'last_modified_by_id' - has_many :created_checklists, class_name: 'Checklist', foreign_key: 'created_by_id' - has_many :modified_checklists, class_name: 'Checklist', foreign_key: 'last_modified_by_id' - has_many :created_checklist_items, class_name: 'ChecklistItem', foreign_key: 'created_by_id' - has_many :modified_checklist_items, class_name: 'ChecklistItem', foreign_key: 'last_modified_by_id' - has_many :modified_comments, class_name: 'Comment', foreign_key: 'last_modified_by_id' - has_many :modified_custom_fields, class_name: 'CustomField', foreign_key: 'last_modified_by_id' - has_many :created_my_module_groups, class_name: 'MyModuleGroup', foreign_key: 'created_by_id' - has_many :created_my_module_tags, class_name: 'MyModuleTag', foreign_key: 'created_by_id' - has_many :created_my_modules, class_name: 'MyModule', foreign_key: 'created_by_id' - has_many :modified_my_modules, class_name: 'MyModule', foreign_key: 'last_modified_by_id' - has_many :archived_my_modules, class_name: 'MyModule', foreign_key: 'archived_by_id' - has_many :restored_my_modules, class_name: 'MyModule', foreign_key: 'restored_by_id' - has_many :created_teams, class_name: 'Team', foreign_key: 'created_by_id' - has_many :modified_teams, class_name: 'Team', foreign_key: 'last_modified_by_id' - has_many :created_projects, class_name: 'Project', foreign_key: 'created_by_id' - has_many :modified_projects, class_name: 'Project', foreign_key: 'last_modified_by_id' - has_many :archived_projects, class_name: 'Project', foreign_key: 'archived_by_id' - has_many :restored_projects, class_name: 'Project', foreign_key: 'restored_by_id' - has_many :modified_reports, class_name: 'Report', foreign_key: 'last_modified_by_id' - has_many :modified_results, class_name: 'Result', foreign_key: 'modified_by_id' - has_many :archived_results, class_name: 'Result', foreign_key: 'archived_by_id' - has_many :restored_results, class_name: 'Result', foreign_key: 'restored_by_id' - has_many :created_sample_groups, class_name: 'SampleGroup', foreign_key: 'created_by_id' - has_many :modified_sample_groups, class_name: 'SampleGroup', foreign_key: 'last_modified_by_id' - has_many :assigned_sample_my_modules, class_name: 'SampleMyModule', foreign_key: 'assigned_by_id' - has_many :created_sample_types, class_name: 'SampleType', foreign_key: 'created_by_id' - has_many :modified_sample_types, class_name: 'SampleType', foreign_key: 'last_modified_by_id' - has_many :modified_samples, class_name: 'Sample', foreign_key: 'last_modified_by_id' + has_many :modified_assets, + class_name: 'Asset', + foreign_key: 'last_modified_by_id' + has_many :created_checklists, + class_name: 'Checklist', + foreign_key: 'created_by_id' + has_many :modified_checklists, + class_name: 'Checklist', + foreign_key: 'last_modified_by_id' + has_many :created_checklist_items, + class_name: 'ChecklistItem', + foreign_key: 'created_by_id' + has_many :modified_checklist_items, + class_name: 'ChecklistItem', + foreign_key: 'last_modified_by_id' + has_many :modified_comments, + class_name: 'Comment', + foreign_key: 'last_modified_by_id' + has_many :modified_custom_fields, + class_name: 'CustomField', + foreign_key: 'last_modified_by_id' + has_many :created_my_module_groups, + class_name: 'MyModuleGroup', + foreign_key: 'created_by_id' + has_many :created_my_module_tags, + class_name: 'MyModuleTag', + foreign_key: 'created_by_id' + has_many :created_my_modules, + class_name: 'MyModule', + foreign_key: 'created_by_id' + has_many :modified_my_modules, + class_name: 'MyModule', + foreign_key: 'last_modified_by_id' + has_many :archived_my_modules, + class_name: 'MyModule', + foreign_key: 'archived_by_id' + has_many :restored_my_modules, + class_name: 'MyModule', + foreign_key: 'restored_by_id' + has_many :created_teams, + class_name: 'Team', + foreign_key: 'created_by_id' + has_many :modified_teams, + class_name: 'Team', + foreign_key: 'last_modified_by_id' + has_many :created_projects, + class_name: 'Project', + foreign_key: 'created_by_id' + has_many :modified_projects, + class_name: 'Project', + foreign_key: 'last_modified_by_id' + has_many :archived_projects, + class_name: 'Project', + foreign_key: 'archived_by_id' + has_many :restored_projects, + class_name: 'Project', + foreign_key: 'restored_by_id' + has_many :modified_reports, + class_name: 'Report', + foreign_key: 'last_modified_by_id' + has_many :modified_results, + class_name: 'Result', + foreign_key: 'modified_by_id' + has_many :archived_results, + class_name: 'Result', + foreign_key: 'archived_by_id' + has_many :restored_results, + class_name: 'Result', + foreign_key: 'restored_by_id' + has_many :created_sample_groups, + class_name: 'SampleGroup', + foreign_key: 'created_by_id' + has_many :modified_sample_groups, + class_name: 'SampleGroup', + foreign_key: 'last_modified_by_id' + has_many :assigned_sample_my_modules, + class_name: 'SampleMyModule', + foreign_key: 'assigned_by_id' + has_many :created_sample_types, + class_name: 'SampleType', + foreign_key: 'created_by_id' + has_many :modified_sample_types, + class_name: 'SampleType', + foreign_key: 'last_modified_by_id' + has_many :modified_samples, + class_name: 'Sample', + foreign_key: 'last_modified_by_id' has_many :modified_steps, class_name: 'Step', foreign_key: 'modified_by_id' has_many :created_tables, class_name: 'Table', foreign_key: 'created_by_id' - has_many :modified_tables, class_name: 'Table', foreign_key: 'last_modified_by_id' + has_many :modified_tables, + class_name: 'Table', + foreign_key: 'last_modified_by_id' has_many :created_tags, class_name: 'Tag', foreign_key: 'created_by_id' - has_many :modified_tags, class_name: 'Tag', foreign_key: 'last_modified_by_id' - has_many :assigned_user_my_modules, class_name: 'UserMyModule', foreign_key: 'assigned_by_id' - has_many :assigned_user_teams, class_name: 'UserTeam', foreign_key: 'assigned_by_id' - has_many :assigned_user_projects, class_name: 'UserProject', foreign_key: 'assigned_by_id' - has_many :added_protocols, class_name: 'Protocol', foreign_key: 'added_by_id', inverse_of: :added_by - has_many :archived_protocols, class_name: 'Protocol', foreign_key: 'archived_by_id', inverse_of: :archived_by - has_many :restored_protocols, class_name: 'Protocol', foreign_key: 'restored_by_id', inverse_of: :restored_by + has_many :modified_tags, + class_name: 'Tag', + foreign_key: 'last_modified_by_id' + has_many :assigned_user_my_modules, + class_name: 'UserMyModule', + foreign_key: 'assigned_by_id' + has_many :assigned_user_teams, + class_name: 'UserTeam', + foreign_key: 'assigned_by_id' + has_many :assigned_user_projects, + class_name: 'UserProject', + foreign_key: 'assigned_by_id' + has_many :added_protocols, + class_name: 'Protocol', + foreign_key: 'added_by_id', + inverse_of: :added_by + has_many :archived_protocols, + class_name: 'Protocol', + foreign_key: 'archived_by_id', + inverse_of: :archived_by + has_many :restored_protocols, + class_name: 'Protocol', + foreign_key: 'restored_by_id', + inverse_of: :restored_by has_many :user_notifications, inverse_of: :user has_many :notifications, through: :user_notifications @@ -166,19 +243,19 @@ class User < ActiveRecord::Base def active_status_str if active? - I18n.t("users.enums.status.active") + I18n.t('users.enums.status.active') else - I18n.t("users.enums.status.pending") + I18n.t('users.enums.status.pending') end end def projects_by_teams(team_id = 0, sort_by = nil, archived = false) archived = archived ? true : false - query = Project.all.joins(:user_projects); - sql = "projects.team_id IN " + - "(SELECT DISTINCT team_id FROM user_teams WHERE user_teams.user_id = ?) " + - "AND (projects.visibility=1 OR user_projects.user_id=?) " + - "AND projects.archived = ? "; + query = Project.all.joins(:user_projects) + sql = 'projects.team_id IN (SELECT DISTINCT team_id ' \ + 'FROM user_teams WHERE user_teams.user_id = ?) ' \ + 'AND (projects.visibility=1 OR user_projects.user_id=?) ' \ + 'AND projects.archived = ? ' case sort_by when "old" @@ -193,17 +270,17 @@ class User < ActiveRecord::Base if team_id > 0 result = query - .where("projects.team_id = ?", team_id) - .where(sql, id, id, archived) - .order(sort) - .distinct - .group_by { |project| project.team } + .where('projects.team_id = ?', team_id) + .where(sql, id, id, archived) + .order(sort) + .distinct + .group_by(&:team) else result = query - .where(sql, id, id, archived) - .order(sort) - .distinct - .group_by { |project| project.team } + .where(sql, id, id, archived) + .order(sort) + .distinct + .group_by(&:team) end result || [] end diff --git a/app/utilities/first_time_data_generator.rb b/app/utilities/first_time_data_generator.rb index 5b4f1a2f8..706d3c827 100644 --- a/app/utilities/first_time_data_generator.rb +++ b/app/utilities/first_time_data_generator.rb @@ -92,7 +92,9 @@ module FirstTimeDataGenerator # old = team.projects.where(name: 'Demo project - qPCR')[0] # old.archive! user i = 1 - while team.projects.where(name: name = "Demo project - qPCR (#{i})").present? + while team.projects.where( + name: name = "Demo project - qPCR (#{i})" + ).present? i += 1 end end diff --git a/app/utilities/protocols_importer.rb b/app/utilities/protocols_importer.rb index fddabeaee..a44e8c897 100644 --- a/app/utilities/protocols_importer.rb +++ b/app/utilities/protocols_importer.rb @@ -10,7 +10,7 @@ module ProtocolsImporter protocol_type: (type == :public ? :in_repository_public : :in_repository_private), published_on: (type == :public ? Time.now : nil), added_by: user, - team: @team + team: team ) # Try to rename record diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 0d330f98f..c7f15a784 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -7,18 +7,21 @@ Rails.application.config.assets.version = '1.0' # Rails.application.config.assets.paths << Emoji.images_path # Precompile additional assets. -# application.js application.css, and all non-JS/CSS in app/assets folder are already added. +# application.js application.css, and all non-JS/CSS +# in app/assets folder are already added. Rails.application.config.assets.precompile += %w(underscore.js) Rails.application.config.assets.precompile += %w(jsPlumb-2.0.4-min.js) Rails.application.config.assets.precompile += %w(jsnetworkx.js) Rails.application.config.assets.precompile += %w(handsontable.full.min.js) Rails.application.config.assets.precompile += %w(users/settings/preferences.js) Rails.application.config.assets.precompile += %w(users/settings/teams.js) -Rails.application.config.assets.precompile += %w(users/settings/teams/add_user_modal.js) +Rails.application.config.assets.precompile += + %w(users/settings/teams/add_user_modal.js) Rails.application.config.assets.precompile += %w(users/settings/team.js) Rails.application.config.assets.precompile += %w(my_modules/activities.js) Rails.application.config.assets.precompile += %w(my_modules/protocols.js) -Rails.application.config.assets.precompile += %w(my_modules/protocols/protocol_status_bar.js) +Rails.application.config.assets.precompile += + %w(my_modules/protocols/protocol_status_bar.js) Rails.application.config.assets.precompile += %w(my_modules/results.js) Rails.application.config.assets.precompile += %w(results/result_tables.js) Rails.application.config.assets.precompile += %w(results/result_assets.js) @@ -35,16 +38,20 @@ Rails.application.config.assets.precompile += %w(samples/sample_datatable.js) Rails.application.config.assets.precompile += %w(projects/index.js) Rails.application.config.assets.precompile += %w(samples/samples_importer.js) Rails.application.config.assets.precompile += %w(projects/canvas.js) -Rails.application.config.assets.precompile += %w(experiments/dropdown_actions.js) +Rails.application.config.assets.precompile += + %w(experiments/dropdown_actions.js) Rails.application.config.assets.precompile += %w(reports/index.js) Rails.application.config.assets.precompile += %w(reports/new.js) Rails.application.config.assets.precompile += %w(protocols/index.js) Rails.application.config.assets.precompile += %w(protocols/header.js) Rails.application.config.assets.precompile += %w(protocols/steps.js) Rails.application.config.assets.precompile += %w(protocols/edit.js) -Rails.application.config.assets.precompile += %w(protocols/import_export/eln_table.js) -Rails.application.config.assets.precompile += %w(protocols/import_export/import.js) -Rails.application.config.assets.precompile += %w(protocols/import_export/export.js) +Rails.application.config.assets.precompile += + %w(protocols/import_export/eln_table.js) +Rails.application.config.assets.precompile += + %w(protocols/import_export/import.js) +Rails.application.config.assets.precompile += + %w(protocols/import_export/export.js) Rails.application.config.assets.precompile += %w(datatables.js) Rails.application.config.assets.precompile += %w(search/index.js) Rails.application.config.assets.precompile += %w(navigation.js) diff --git a/config/routes.rb b/config/routes.rb index b3687531b..62555b648 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -104,7 +104,7 @@ Rails.application.routes.draw do to: 'user_notifications#index', as: 'notifications' - resources :teams, only: [] do + resources :teams do resources :samples, only: [:new, :create] resources :sample_types, except: [:show, :new] do get 'sample_type_element', to: 'sample_types#sample_type_element'