Module: EnjuLeaf::EnjuUser::ClassMethods
- Defined in:
- lib/enju_leaf/user.rb
Class Method Summary collapse
-
.export(options = {format: :txt}) ⇒ Object
ユーザの情報をエクスポートします。.
Instance Method Summary collapse
- #enju_leaf_user_model ⇒ Object
-
#lock_expired_users ⇒ Object
有効期限切れのユーザを一括で使用不可にします。.
Class Method Details
.export(options = {format: :txt}) ⇒ Object
ユーザの情報をエクスポートします。
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/enju_leaf/user.rb', line 68 def self.export( = {format: :txt}) header = %w( username full_name full_name_transcription email user_number role user_group library locale locked required_role created_at updated_at expired_at keyword_list note ) header += %w( checkout_icalendar_token save_checkout_history ) if defined? EnjuCirculation header << "save_search_history" if defined? EnjuSearchLog header << "share_bookmarks" if defined? EnjuBookmark lines = [] User.all.map{|u| line = [] line << u.username line << u.try(:profile).try(:full_name) line << u.try(:profile).try(:full_name_transcription) line << u.email line << u.try(:profile).try(:user_number) line << u.role.try(:name) line << u.try(:profile).try(:user_group).try(:name) line << u.try(:profile).try(:library).try(:name) line << u.try(:profile).try(:locale) line << u.access_locked? line << u.try(:profile).try(:required_role).try(:name) line << u.created_at line << u.updated_at line << u.try(:profile).try(:expired_at) line << u.try(:profile).try(:keyword_list).try(:split).try(:join, "//") line << u.try(:profile).try(:note) if defined? EnjuCirculation line << u.try(:profile).try(:checkout_icalendar_token) line << u.try(:profile).try(:save_checkout_history) end if defined? EnjuSearchLog line << u.try(:profile).try(:save_search_history) end if defined? EnjuBookmark line << u.try(:profile).try(:share_bookmarks) end lines << line } if [:format] == :txt lines.map{|line| line.to_csv(col_sep: "\t")}.unshift(header.to_csv(col_sep: "\t")).join else lines end end |
Instance Method Details
#enju_leaf_user_model ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/enju_leaf/user.rb', line 8 def enju_leaf_user_model include InstanceMethods scope :administrators, -> { joins(:role).where('roles.name = ?', 'Administrator') } scope :librarians, -> { joins(:role).where('roles.name = ? OR roles.name = ?', 'Administrator', 'Librarian') } scope :suspended, -> { where('locked_at IS NOT NULL') } has_one :profile if defined?(EnjuBiblio) has_many :import_requests has_many :picture_files, as: :picture_attachable, dependent: :destroy end has_one :user_has_role, dependent: :destroy has_one :role, through: :user_has_role belongs_to :user_group belongs_to :library belongs_to :required_role, class_name: 'Role', foreign_key: 'required_role_id' accepts_nested_attributes_for :user_has_role validates :username, presence: true, uniqueness: true, format: { with: /\A[0-9A-Za-z][0-9A-Za-z_\-]*[0-9A-Za-z]\z/ } validates :email, format: Devise::email_regexp, allow_blank: true, uniqueness: true validates_date :expired_at, allow_blank: true if: :password_required? do |v| v.validates_presence_of :password v.validates_confirmation_of :password v.validates_length_of :password, allow_blank: true, within: Devise::password_length end #validates_presence_of :email, :email_confirmation, on: :create, if: proc{|user| !user.operator.try(:has_role?, 'Librarian')} #validates_confirmation_of :email, on: :create #, if: proc{|user| !user.operator.try(:has_role?, 'Librarian')} before_validation :set_lock_information before_destroy :check_role_before_destroy before_save :check_expiration after_create :set_confirmation extend FriendlyId friendly_id :username #has_paper_trail normalize_attributes :username normalize_attributes :email, with: :strip attr_accessor :password_not_verified, :update_own_account, :auto_generated_password, :locked, :current_password #, :agent_id paginates_per 10 # 有効期限切れのユーザを一括で使用不可にします。 def lock_expired_users User.find_each do |user| user.lock_access! if user.expired? and user.active_for_authentication? end end # ユーザの情報をエクスポートします。 # @param [Hash] options def self.export( = {format: :txt}) header = %w( username full_name full_name_transcription email user_number role user_group library locale locked required_role created_at updated_at expired_at keyword_list note ) header += %w( checkout_icalendar_token save_checkout_history ) if defined? EnjuCirculation header << "save_search_history" if defined? EnjuSearchLog header << "share_bookmarks" if defined? EnjuBookmark lines = [] User.all.map{|u| line = [] line << u.username line << u.try(:profile).try(:full_name) line << u.try(:profile).try(:full_name_transcription) line << u.email line << u.try(:profile).try(:user_number) line << u.role.try(:name) line << u.try(:profile).try(:user_group).try(:name) line << u.try(:profile).try(:library).try(:name) line << u.try(:profile).try(:locale) line << u.access_locked? line << u.try(:profile).try(:required_role).try(:name) line << u.created_at line << u.updated_at line << u.try(:profile).try(:expired_at) line << u.try(:profile).try(:keyword_list).try(:split).try(:join, "//") line << u.try(:profile).try(:note) if defined? EnjuCirculation line << u.try(:profile).try(:checkout_icalendar_token) line << u.try(:profile).try(:save_checkout_history) end if defined? EnjuSearchLog line << u.try(:profile).try(:save_search_history) end if defined? EnjuBookmark line << u.try(:profile).try(:share_bookmarks) end lines << line } if [:format] == :txt lines.map{|line| line.to_csv(col_sep: "\t")}.unshift(header.to_csv(col_sep: "\t")).join else lines end end end |
#lock_expired_users ⇒ Object
有効期限切れのユーザを一括で使用不可にします。
60 61 62 63 64 |
# File 'lib/enju_leaf/user.rb', line 60 def lock_expired_users User.find_each do |user| user.lock_access! if user.expired? and user.active_for_authentication? end end |