diff --git a/app/models/theme.rb b/app/models/theme.rb index 3df17bd..11cc32e 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -1,18 +1,24 @@ class Theme < ActiveRecord::Base - #associations between tables + ## + # Associations has_and_belongs_to_many :questions, join_table: "questions_themes" has_and_belongs_to_many :guidances, join_table: "themes_in_guidance" - has_and_belongs_to_many :new_questions, join_table: "new_questions_themes" - -# accepts_nested_attributes_for :guidances -# accepts_nested_attributes_for :questions - + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 attr_accessible :guidance_ids , :as => [:default, :admin] attr_accessible :question_ids, :as => [:default, :admin] attr_accessible :description, :title, :locale , :as => [:default, :admin] + + # EVALUATE CLASS AND INSTANCE METHODS BELOW + # + # What do they do? do they do it efficiently, and do we need them? + + + ## # returns the title of the theme # diff --git a/app/models/user.rb b/app/models/user.rb index 6a14c60..82f659d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,58 +1,66 @@ class User < ActiveRecord::Base include GlobalHelpers - - # Include default devise modules. Others available are: - # :token_authenticatable, :confirmable, - # :lockable, :timeoutable and :omniauthable + ## + # Devise + # Include default devise modules. Others available are: + # :token_authenticatable, :confirmable, + # :lockable, :timeoutable and :omniauthable devise :invitable, :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable, :omniauth_providers => [:shibboleth] - #associations between tables - has_many :answers - has_many :project_groups, :dependent => :destroy - has_many :user_role_types, through: :user_org_roles - belongs_to :language - - belongs_to :org - - has_many :projects, through: :project_groups do - def filter(query) - return self unless query.present? - - t = self.arel_table - q = "%#{query}%" - - conditions = t[:title].matches(q) - - columns = %i( - grant_number identifier description principal_investigator data_contact - ) - columns = ['grant_number', 'identifier', 'description', 'principal_investigator', 'data_contact'] - - columns.each {|col| conditions = conditions.or(t[col].matches(q)) } - - self.where(conditions) - end + ## + # Associations + has_and_belongs_to_many :perms, join_table: :users_perms + belongs_to :language + belongs_to :org + has_many :answers + has_many :notes + has_many :roles, dependent: :destroy + has_many :projects, through: :roles do + def filter(query) + return self unless query.present? + t = self.arel_table + q = "%#{query}%" + conditions = t[:title].matches(q) + columns = %i( + grant_number identifier description principal_investigator data_contact + ) + columns = ['grant_number', 'identifier', 'description', 'principal_investigator', 'data_contact'] + columns.each {|col| conditions = conditions.or(t[col].matches(q)) } + self.where(conditions) end + end - has_and_belongs_to_many :roles, :join_table => :users_roles + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 + accepts_nested_attributes_for :roles + attr_accessible :password_confirmation, :encrypted_password, :remember_me, :id, :email, + :firstname, :last_login,:login_count, :orcid_id, :password, :shibboleth_id, + :user_status_id, :surname, :user_type_id, :organisation_id, :skip_invitation, + :other_organisation, :accept_terms, :role_ids, :dmponline3, :api_token, + :organisation, :language, :language_id - has_many :plan_sections + validates :email, email: true, allow_nil: true, uniqueness: true - accepts_nested_attributes_for :roles - attr_accessible :password_confirmation, :encrypted_password, :remember_me, :id, :email, - :firstname, :last_login,:login_count, :orcid_id, :password, :shibboleth_id, - :user_status_id, :surname, :user_type_id, :organisation_id, :skip_invitation, - :other_organisation, :accept_terms, :role_ids, :dmponline3, :api_token, - :organisation, :language, :language_id + ## + # Settings + # FIXME: The duplication in the block is to set defaults. It might be better if + # they could be set in Settings::PlanList itself, if possible. + has_settings :plan_list, class_name: 'Settings::PlanList' do |s| + s.key :plan_list, defaults: { columns: Settings::PlanList::DEFAULT_COLUMNS } + end - #validates :email, email: true, allow_nil: true, uniqueness: true - # FIXME: The duplication in the block is to set defaults. It might be better if - # they could be set in Settings::PlanList itself, if possible. - has_settings :plan_list, class_name: 'Settings::PlanList' do |s| - s.key :plan_list, defaults: { columns: Settings::PlanList::DEFAULT_COLUMNS } - end + + + # EVALUATE CLASS AND INSTANCE METHODS BELOW + # + # What do they do? do they do it efficiently, and do we need them? + + + + ## # gives either the name of the user, or the email if name unspecified diff --git a/app/models/user_org_role.rb b/app/models/user_org_role.rb deleted file mode 100644 index 10fca3c..0000000 --- a/app/models/user_org_role.rb +++ /dev/null @@ -1,9 +0,0 @@ -class UserOrgRole < ActiveRecord::Base - attr_accessible :organisation_id, :user_id, :user_role_type_id, :as => [:default, :admin] - - #associations between tables - belongs_to :user - belongs_to :organisation - belongs_to :user_role_type - -end diff --git a/app/models/users_perm.rb b/app/models/users_perm.rb deleted file mode 100644 index 38a6cd3..0000000 --- a/app/models/users_perm.rb +++ /dev/null @@ -1,4 +0,0 @@ -class UsersPerm < ActiveRecord::Base - belongs_to :user - belongs_to :perm -end \ No newline at end of file