Class: User

Inherits:
ActiveRecord::Base show all
Defined in:
app/models/user.rb

Overview

Representation of a user in the database

RLetters keeps track of users so that it can send e-mails regarding background jobs and keep a set of customizable user options.

Defined Under Namespace

Classes: ParameterSanitizer

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveRecord::Base

logger

Instance Attribute Details

#csl_style_idInteger

Returns User's preferred citation style (id of a CslStyle in database)

Returns:

  • (Integer)

    User's preferred citation style (id of a CslStyle in database)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

#datasetsArray<Dataset>

Returns All datasets created by the user (has_many)

Returns:

  • (Array<Dataset>)

    All datasets created by the user (has_many)

Raises:

  • (RecordInvalid)

    if any of the datasets are invalid (validates_associated)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

#emailString

Returns E-mail address

Returns:

  • (String)

    E-mail address



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

#languageString

Returns Locale code of user's preferred language

Returns:

  • (String)

    Locale code of user's preferred language

Raises:

  • (RecordInvalid)

    if the language is missing (validates :presence)

  • (RecordInvalid)

    if the language is not a valid language code (validates :format)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

#librariesArray<Library>

Returns All library links added by the user (has_many)

Returns:

  • (Array<Library>)

    All library links added by the user (has_many)

Raises:

  • (RecordInvalid)

    if any of the libraries are invalid (validates_associated)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

#nameString

Returns Full name

Returns:

  • (String)

    Full name

Raises:

  • (RecordInvalid)

    if the name is missing (validates :presence)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

#passwordString

Returns Password (encrypted, from Devise)

Returns:

  • (String)

    Password (encrypted, from Devise)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

#password_confirmationString

Returns Password confirmation field (encrypted, from Devise)

Returns:

  • (String)

    Password confirmation field (encrypted, from Devise)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

#per_pageInteger

Returns Number of search results to display per page

Returns:

  • (Integer)

    Number of search results to display per page

Raises:

  • (RecordInvalid)

    if per_page is missing (validates :presence)

  • (RecordInvalid)

    if per_page is not an integer (validates :numericality)

  • (RecordInvalid)

    if per_page is negative (validates :inclusion)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

#remember_meBoolean

Returns Whether to keep user logged in (from Devise)

Returns:

  • (Boolean)

    Whether to keep user logged in (from Devise)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

#timezoneString

Returns User's timezone, in Rails' format

Returns:

  • (String)

    User's timezone, in Rails' format

Raises:

  • (RecordInvalid)

    if the timezone is missing (validates :presence)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

Instance Method Details

#csl_styleCslStyle

Convert the csl_style_id to a CslStyle (or nil)

Examples:

Format a document with a user's CSL style

@document.to_csl_entry(@user.csl_style)
# Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!

Returns:

  • (CslStyle)

    the user's CSL style (or nil)



71
72
73
# File 'app/models/user.rb', line 71

def csl_style
  CslStyle.find(csl_style_id) rescue nil
end