Add and inherit from ApplicationRecord to match Rails 5.0 style
This commit is contained in:
parent
8c6d48da86
commit
abe847c0ee
34 changed files with 56 additions and 66 deletions
3
app/models/application_record.rb
Normal file
3
app/models/application_record.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class ApplicationRecord < ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
# encoding: utf-8
|
||||
class Article < ActiveRecord::Base
|
||||
class Article < ApplicationRecord
|
||||
include PriceCalculation
|
||||
|
||||
# @!attribute name
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Article category
|
||||
class ArticleCategory < ActiveRecord::Base
|
||||
class ArticleCategory < ApplicationRecord
|
||||
|
||||
# @!attribute name
|
||||
# @return [String] Title of the category.
|
||||
|
@ -40,4 +40,3 @@ class ArticleCategory < ActiveRecord::Base
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class ArticlePrice < ActiveRecord::Base
|
||||
class ArticlePrice < ApplicationRecord
|
||||
include PriceCalculation
|
||||
|
||||
# @!attribute price
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
class Assignment < ActiveRecord::Base
|
||||
|
||||
class Assignment < ApplicationRecord
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :task
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class BankAccount < ActiveRecord::Base
|
||||
class BankAccount < ApplicationRecord
|
||||
|
||||
has_many :bank_transactions, dependent: :destroy
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class BankTransaction < ActiveRecord::Base
|
||||
class BankTransaction < ApplicationRecord
|
||||
|
||||
# @!attribute external_id
|
||||
# @return [String] Unique Identifier of the transaction within the bank account.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class Delivery < ActiveRecord::Base
|
||||
class Delivery < ApplicationRecord
|
||||
|
||||
belongs_to :supplier
|
||||
belongs_to :invoice
|
||||
|
@ -39,13 +39,11 @@ class Delivery < ActiveRecord::Base
|
|||
end
|
||||
|
||||
protected
|
||||
|
||||
|
||||
def stock_articles_must_be_unique
|
||||
unless stock_changes.reject{|sc| sc.marked_for_destruction?}.map {|sc| sc.stock_article.id}.uniq!.nil?
|
||||
errors.add(:base, I18n.t('model.delivery.each_stock_article_must_be_unique'))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class FinancialLink < ActiveRecord::Base
|
||||
class FinancialLink < ApplicationRecord
|
||||
has_many :bank_transactions
|
||||
has_many :financial_transactions
|
||||
has_many :invoices
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# financial transactions are the foodcoop internal financial transactions
|
||||
# only ordergroups have an account balance and are happy to transfer money
|
||||
class FinancialTransaction < ActiveRecord::Base
|
||||
class FinancialTransaction < ApplicationRecord
|
||||
belongs_to :ordergroup
|
||||
belongs_to :user
|
||||
belongs_to :financial_link
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class FinancialTransactionClass < ActiveRecord::Base
|
||||
class FinancialTransactionClass < ApplicationRecord
|
||||
has_many :financial_transaction_types, dependent: :destroy
|
||||
|
||||
validates :name, presence: true
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class FinancialTransactionType < ActiveRecord::Base
|
||||
class FinancialTransactionType < ApplicationRecord
|
||||
belongs_to :financial_transaction_class
|
||||
has_many :financial_transactions, dependent: :restrict_with_exception
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# encoding: utf-8
|
||||
# Groups organize the User.
|
||||
# A Member gets the roles from the Group
|
||||
class Group < ActiveRecord::Base
|
||||
class Group < ApplicationRecord
|
||||
include FindEachWithOrder
|
||||
include MarkAsDeletedWithName
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# A GroupOrder represents an Order placed by an Ordergroup.
|
||||
class GroupOrder < ActiveRecord::Base
|
||||
class GroupOrder < ApplicationRecord
|
||||
include FindEachWithOrder
|
||||
|
||||
attr_accessor :group_order_articles_attributes
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# A GroupOrderArticle stores the sum of how many items of an OrderArticle are ordered as part of a GroupOrder.
|
||||
# The chronologically order of the Ordergroup - activity are stored in GroupOrderArticleQuantity
|
||||
#
|
||||
class GroupOrderArticle < ActiveRecord::Base
|
||||
class GroupOrderArticle < ApplicationRecord
|
||||
|
||||
belongs_to :group_order
|
||||
belongs_to :order_article
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# stores the quantity, tolerance and timestamp of an GroupOrderArticle
|
||||
# Considers every update of an article-order, so may rows for one group_order_article ar possible.
|
||||
|
||||
class GroupOrderArticleQuantity < ActiveRecord::Base
|
||||
class GroupOrderArticleQuantity < ApplicationRecord
|
||||
|
||||
belongs_to :group_order_article
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'digest/sha1'
|
||||
|
||||
# Invites are created by foodcoop users to invite a new user into the foodcoop and their order group.
|
||||
class Invite < ActiveRecord::Base
|
||||
class Invite < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :group
|
||||
|
||||
|
@ -13,9 +13,9 @@ class Invite < ActiveRecord::Base
|
|||
validate :email_not_already_registered, :on => :create
|
||||
|
||||
before_validation :set_token_and_expires_at
|
||||
|
||||
|
||||
protected
|
||||
|
||||
|
||||
# Before validation, set token and expires_at.
|
||||
def set_token_and_expires_at
|
||||
self.token = Digest::SHA1.hexdigest(Time.now.to_s + rand(100).to_s)
|
||||
|
@ -32,4 +32,3 @@ class Invite < ActiveRecord::Base
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class Invoice < ActiveRecord::Base
|
||||
class Invoice < ApplicationRecord
|
||||
include CustomFields
|
||||
|
||||
belongs_to :supplier
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class MailDeliveryStatus < ActiveRecord::Base
|
||||
class MailDeliveryStatus < ApplicationRecord
|
||||
self.table_name = 'mail_delivery_status'
|
||||
|
||||
belongs_to :user, foreign_key: 'email', primary_key: 'email'
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
class Membership < ActiveRecord::Base
|
||||
|
||||
class Membership < ApplicationRecord
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :group
|
||||
|
||||
before_destroy :check_last_admin
|
||||
|
||||
|
||||
|
||||
protected
|
||||
|
||||
# check if this is the last admin-membership and deny
|
||||
def check_last_admin
|
||||
raise I18n.t('model.membership.no_admin_delete') if self.group.role_admin? && self.group.memberships.size == 1 && Group.where(role_admin: true).count == 1
|
||||
raise I18n.t('model.membership.no_admin_delete') if self.group.role_admin? && self.group.memberships.size == 1 && Group.where(role_admin: true).count == 1
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
class Order < ActiveRecord::Base
|
||||
class Order < ApplicationRecord
|
||||
attr_accessor :ignore_warnings
|
||||
|
||||
# Associations
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# An OrderArticle represents a single Article that is part of an Order.
|
||||
class OrderArticle < ActiveRecord::Base
|
||||
class OrderArticle < ApplicationRecord
|
||||
include FindEachWithOrder
|
||||
|
||||
attr_reader :update_global_price
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class OrderComment < ActiveRecord::Base
|
||||
class OrderComment < ApplicationRecord
|
||||
|
||||
belongs_to :order
|
||||
belongs_to :user
|
||||
|
@ -6,4 +6,3 @@ class OrderComment < ActiveRecord::Base
|
|||
validates_presence_of :order_id, :user_id, :text
|
||||
validates_length_of :text, :minimum => 3
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class PeriodicTaskGroup < ActiveRecord::Base
|
||||
class PeriodicTaskGroup < ApplicationRecord
|
||||
has_many :tasks, dependent: :destroy
|
||||
|
||||
def has_next_task?
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class SharedArticle < ActiveRecord::Base
|
||||
class SharedArticle < ApplicationRecord
|
||||
|
||||
# connect to database from sharedLists-Application
|
||||
SharedArticle.establish_connection(FoodsoftConfig[:shared_lists])
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class SharedSupplier < ActiveRecord::Base
|
||||
class SharedSupplier < ApplicationRecord
|
||||
|
||||
# connect to database from sharedLists-Application
|
||||
SharedSupplier.establish_connection(FoodsoftConfig[:shared_lists])
|
||||
|
@ -33,4 +33,3 @@ class SharedSupplier < ActiveRecord::Base
|
|||
methods
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class StockChange < ActiveRecord::Base
|
||||
class StockChange < ApplicationRecord
|
||||
belongs_to :delivery
|
||||
belongs_to :order
|
||||
belongs_to :stock_taking
|
||||
|
@ -16,4 +16,3 @@ class StockChange < ActiveRecord::Base
|
|||
stock_article.update_quantity!
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class StockTaking < ActiveRecord::Base
|
||||
class StockTaking < ApplicationRecord
|
||||
|
||||
has_many :stock_changes, :dependent => :destroy
|
||||
has_many :stock_articles, :through => :stock_changes
|
||||
|
@ -11,4 +11,3 @@ class StockTaking < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# encoding: utf-8
|
||||
class Supplier < ActiveRecord::Base
|
||||
class Supplier < ApplicationRecord
|
||||
include MarkAsDeletedWithName
|
||||
include CustomFields
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
class Task < ActiveRecord::Base
|
||||
class Task < ApplicationRecord
|
||||
has_many :assignments, :dependent => :destroy
|
||||
has_many :users, :through => :assignments
|
||||
belongs_to :workgroup
|
||||
|
@ -89,7 +89,7 @@ class Task < ActiveRecord::Base
|
|||
list = ids.split(",").map(&:to_i)
|
||||
new_users = (list - users.collect(&:id)).uniq
|
||||
old_users = users.reject { |user| list.include?(user.id) }
|
||||
|
||||
|
||||
self.class.transaction do
|
||||
# delete old assignments
|
||||
if old_users.any?
|
||||
|
@ -112,7 +112,7 @@ class Task < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def user_list
|
||||
@user_list ||= users.collect(&:id).join(", ")
|
||||
end
|
||||
|
@ -126,4 +126,3 @@ class Task < ActiveRecord::Base
|
|||
true
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'digest/sha1'
|
||||
# specific user rights through memberships (see Group)
|
||||
class User < ActiveRecord::Base
|
||||
class User < ApplicationRecord
|
||||
include CustomFields
|
||||
#TODO: acts_as_paraniod ??
|
||||
|
||||
|
@ -19,7 +19,7 @@ class User < ActiveRecord::Base
|
|||
has_many :send_messages, :class_name => "Message", :foreign_key => "sender_id"
|
||||
has_many :created_orders, :class_name => 'Order', :foreign_key => 'created_by_user_id', :dependent => :nullify
|
||||
has_many :mail_delivery_status, :class_name => 'MailDeliveryStatus', :foreign_key => 'email', :primary_key => 'email'
|
||||
|
||||
|
||||
attr_accessor :password, :settings_attributes
|
||||
|
||||
scope :deleted, -> { where.not(deleted_at: nil) }
|
||||
|
@ -27,7 +27,7 @@ class User < ActiveRecord::Base
|
|||
|
||||
# makes the current_user (logged-in-user) available in models
|
||||
cattr_accessor :current_user
|
||||
|
||||
|
||||
validates_presence_of :email
|
||||
validates_presence_of :password, :on => :create
|
||||
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
|
||||
|
@ -51,14 +51,14 @@ class User < ActiveRecord::Base
|
|||
settings.defaults['messages'] = { 'send_as_email' => true } unless settings.messages
|
||||
settings.defaults['notify'] = { 'upcoming_tasks' => true } unless settings.notify
|
||||
end
|
||||
|
||||
|
||||
after_save do
|
||||
settings_attributes.each do |key, value|
|
||||
value.each do |k, v|
|
||||
case v
|
||||
when '1'
|
||||
value[k] = true
|
||||
when '0'
|
||||
when '0'
|
||||
value[k] = false
|
||||
end
|
||||
end
|
||||
|
@ -88,11 +88,11 @@ class User < ActiveRecord::Base
|
|||
end.reduce(:and)
|
||||
User.where(match_nick.or match_name)
|
||||
end
|
||||
|
||||
|
||||
def locale
|
||||
settings.profile['language']
|
||||
end
|
||||
|
||||
|
||||
def name
|
||||
[first_name, last_name].join(" ")
|
||||
end
|
||||
|
@ -100,7 +100,7 @@ class User < ActiveRecord::Base
|
|||
def receive_email?
|
||||
settings.messages['send_as_email'] && email.present?
|
||||
end
|
||||
|
||||
|
||||
# Sets the user's password. It will be stored encrypted along with a random salt.
|
||||
def set_password
|
||||
unless password.blank?
|
||||
|
@ -108,12 +108,12 @@ class User < ActiveRecord::Base
|
|||
self.password_hash, self.password_salt = Digest::SHA1.hexdigest(password + salt), salt
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Returns true if the password argument matches the user's password.
|
||||
def has_password(password)
|
||||
Digest::SHA1.hexdigest(password + self.password_salt) == self.password_hash
|
||||
end
|
||||
|
||||
|
||||
# Returns a random password.
|
||||
def new_random_password(size = 3)
|
||||
c = %w(b c d f g h j k l m n p qu r s t v w x z ch cr fr nd ng nk nt ph pr rd sh sl sp st th tr)
|
||||
|
@ -144,7 +144,7 @@ class User < ActiveRecord::Base
|
|||
def role_admin?
|
||||
groups.detect {|group| group.role_admin?}
|
||||
end
|
||||
|
||||
|
||||
# Checks the finance role
|
||||
def role_finance?
|
||||
groups.detect {|group| group.role_finance?}
|
||||
|
@ -228,4 +228,3 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class Document < ActiveRecord::Base
|
||||
class Document < ApplicationRecord
|
||||
include ActsAsTree
|
||||
|
||||
belongs_to :created_by, class_name: 'User', foreign_key: 'created_by_user_id'
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require "base32"
|
||||
|
||||
class Message < ActiveRecord::Base
|
||||
class Message < ApplicationRecord
|
||||
belongs_to :sender, :class_name => "User", :foreign_key => "sender_id"
|
||||
belongs_to :group, :class_name => "Group", :foreign_key => "group_id"
|
||||
belongs_to :reply_to_message, :class_name => "Message", :foreign_key => "reply_to"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class Page < ActiveRecord::Base
|
||||
class Page < ApplicationRecord
|
||||
include ActsAsTree
|
||||
|
||||
belongs_to :user, :foreign_key => 'updated_by'
|
||||
|
|
Loading…
Reference in a new issue