module Decidim::Authorable

This concern contains the logic related to single authorship.

Sometimes authorship may belong to a single user or be shared among coauthors, in this latest case the Coauthorable concern should be used instead of Authorable.

Public Instance Methods

author_belongs_to_organization() click to toggle source
# File lib/decidim/authorable.rb, line 70
def author_belongs_to_organization
  return if !author || !organization

  errors.add(:author, :invalid) unless author == organization || author.respond_to?(:organization) && author.organization == organization
end
authored_by?(other_author) click to toggle source

Checks whether the user is author of the given resource, either directly authoring it or via a user group.

user - the user to check for authorship

# File lib/decidim/authorable.rb, line 37
def authored_by?(other_author)
  other_author == author || other_author.respond_to?(:user_groups) && other_author.user_groups.include?(user_group)
end
normalized_author() click to toggle source

Returns the normalized author, whether it's a user group or a user. Ideally this should be the author method, but it's pending a refactor.

Returns an Author, a UserGroup or nil.

# File lib/decidim/authorable.rb, line 45
def normalized_author
  user_group || author
end
official?() click to toggle source

Public: Checks whether the resource is official or not.

Returns a boolean.

# File lib/decidim/authorable.rb, line 52
def official?
  decidim_author_type == Decidim::Organization.name
end
user_group_membership() click to toggle source
# File lib/decidim/authorable.rb, line 64
def user_group_membership
  return unless user_group

  errors.add :user_group, :invalid unless user_group.users.include? author
end
verified_user_group() click to toggle source
# File lib/decidim/authorable.rb, line 58
def verified_user_group
  return unless user_group

  errors.add :user_group, :invalid unless user_group.verified?
end