0820badcc3
This provides a way to set the level of involvement that a user has with a collection, and from which we determine the level of notifications to send. Users can be access-only, watching, or being notified about everything. If you're access-only, you won't get an notifications. If you're watching, you'll only get notifications for the items you're watching (which includes the items you've been assigned, have commented on, etc). If you're set to everything you'll get notifications about all activity in that collection. This change replaces our previous concept of subscriptions. Where previously you'd subscribe to a collection to get notifications in it, now you'll simply set the notification level on your access.
40 lines
1.0 KiB
Ruby
40 lines
1.0 KiB
Ruby
module Bucket::Accessible
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
has_many :accesses, dependent: :delete_all do
|
|
def revise(granted: [], revoked: [])
|
|
transaction do
|
|
grant_to granted
|
|
revoke_from revoked
|
|
end
|
|
end
|
|
|
|
def grant_to(users)
|
|
Access.insert_all Array(users).collect { |user| { bucket_id: proxy_association.owner.id, user_id: user.id } }
|
|
end
|
|
|
|
def revoke_from(users)
|
|
destroy_by user: users unless proxy_association.owner.all_access?
|
|
end
|
|
end
|
|
|
|
has_many :users, through: :accesses
|
|
has_many :access_only_users, -> { merge(Access.access_only) }, through: :accesses, source: :user
|
|
|
|
scope :all_access, -> { where(all_access: true) }
|
|
|
|
after_create -> { accesses.grant_to creator }
|
|
after_save_commit :grant_access_to_everyone
|
|
end
|
|
|
|
def access_for(user)
|
|
accesses.find_by(user: user)
|
|
end
|
|
|
|
private
|
|
def grant_access_to_everyone
|
|
accesses.grant_to(account.users) if all_access_previously_changed?(to: true)
|
|
end
|
|
end
|