Sha256: 39f08de427ac5a67b60d3ba311be68deb90b168de4a0ff9d6d19780e24dc1829

Contents?: true

Size: 1013 Bytes

Versions: 42

Compression:

Stored size: 1013 Bytes

Contents

class Author < ActiveRecord::Base
  belongs_to :user_group, class_name: Edgarj::UserGroup
  has_many :books

  validates_presence_of :name

  # declare 'has_many :authors' at Edgarj::UserGroup here
  Edgarj::UserGroup.has_many :authors

  # 1. admin and author_reader can access all of authors
  # 1. The user, who belongs to AUTHOR_ASSIGNEE user_group, can access
  #    the authors belongs to the user_group.
  # 1. otherwise, cannot
  scope :user_scoped, lambda{|user, context, id_target|
    if user.admin? || 
       user.user_groups.where('kind=? AND name in (?)',
          Edgarj::UserGroup::Kind::ROLE,
          ['author/reader', 'author/admin']).count > 0
      where('1=1')
    else
      joins(user_group: :user_group_users).
      where(
        'edgarj_user_groups.kind'          => Edgarj::UserGroup::Kind::AUTHOR_ASSIGNEE,
        'edgarj_user_group_users.user_id'  => user.id)
    end
  }

  def initialize(attrs = {})
    super
   #self.adrs = Edgarj::Address.new if self.adrs == nil
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
edgarj-4.06.10 test/dummy/app/models/author.rb
edgarj-4.06.09 test/dummy/app/models/author.rb
edgarj-4.06.07 test/dummy/app/models/author.rb
edgarj-4.06.05 test/dummy/app/models/author.rb
edgarj-4.06.04 test/dummy/app/models/author.rb
edgarj-4.06.03 test/dummy/app/models/author.rb
edgarj-4.06.02 test/dummy/app/models/author.rb
edgarj-4.06.01 test/dummy/app/models/author.rb
edgarj-4.06.00 test/dummy/app/models/author.rb
edgarj-4.05.04 test/dummy/app/models/author.rb
edgarj-4.05.03 test/dummy/app/models/author.rb
edgarj-4.05.02 test/dummy/app/models/author.rb
edgarj-4.05.01 test/dummy/app/models/author.rb
edgarj-4.05.00 test/dummy/app/models/author.rb
edgarj-4.04.01 test/dummy/app/models/author.rb
edgarj-4.04.00 test/dummy/app/models/author.rb
edgarj-4.03.00 test/dummy/app/models/author.rb
edgarj-4.02.00 test/dummy/app/models/author.rb
edgarj-4.01.01 test/dummy/app/models/author.rb
edgarj-4.01.00 test/dummy/app/models/author.rb