class DocumentPolicy < ApplicationPolicy
  def index?
    gds_editor? || departmental_editor? || writer?
  end

  alias_method :new?, :index?
  alias_method :create?, :index?
  alias_method :edit?, :index?
  alias_method :update?, :index?
  alias_method :show?, :index?
  #FIXME fix this, attachments are using the wrong policy
  alias_method :destroy?, :index?

  def publish?
    gds_editor? || departmental_editor?
  end

  alias_method :unpublish?, :publish?
  alias_method :discard?, :publish?

  def user_organisation_owns_document_type?
    document_class.organisations.include?(user.organisation_content_id)
  end

  def departmental_editor?
    user_organisation_owns_document_type? && user.permissions.include?('editor')
  end

  def writer?
    user_organisation_owns_document_type?
  end

  def gds_editor?
    user.gds_editor?
  end
end

class DocumentPolicy < ApplicationPolicy
  def index?
    gds_editor? || departmental_editor? || writer?
  end

  alias_method :new?, :index?
  alias_method :create?, :index?
  alias_method :edit?, :index?
  alias_method :update?, :index?
  alias_method :show?, :index?
  #FIXME fix this, attachments are using the wrong policy
  alias_method :destroy?, :index?

  def publish?
    gds_editor? || departmental_editor?
  end

  alias_method :unpublish?, :publish?
  alias_method :discard?, :publish?
end

Remove redundant methods from DocumentPolicy
Remove redundant methods from DocumentPolicy

DocumentPolicy inherits from ApplicationPolicy where these methods are
already defined, so we can drop them.
