<commit_before># frozen_string_literal: true
module Hyrax
  ##
  # Holds policy data about the workflow and permissions applied objects when
  # they are deposited through an Administrative Set or a Collection. Each
  # template record has a {#source} (through {#source_id}); the template's
  # rules inform the behavior of objects deposited through that {#source_model}.
  #
  # The {PermissionTemplate} specifies:
  #
  # - an {#active_workflow} that the object will enter and be processed through.
  # - {#access_grants} that can be applied to each object (especially at deposit
  #   time).
  # - an embargo configuration ({#release_date} {#release_period}) for default
  #   embargo behavior.
  #
  # @todo write up what "default embargo behavior", when it is applied, and how
  #   it interacts with embargoes specified by user input.
  #
  # @see Hyrax::AdministrativeSet
  class PermissionTemplate < ActiveRecord::Base # rubocop:disable Metrics/ClassLength
    self.table_name = 'permission_templates'

    ##
    # @!attribute [rw] source_id
    #   @return [String] identifier for the {Collection} or {AdministrativeSet}
    #     to which this template applies.
    # @!attribute [rw] access_grants
    #   @return [Hyrax::PermissionTemplateAccess]
    # @!attribute [rw] active_workflow
    #   @return [Sipity::Workflow]
    # @!attribute [rw] available_workflows
    #   @return [Enumerable<Sipity::Workflow>]
    has_many :access_grants, class_name: 'Hyrax::PermissionTemplateAccess', dependent: :destroy
    accepts_nested_attributes_for :access_grants, reject_if: :all_blank

    # The list of workflows that could be activated; It includes the active workflow
    has_many :available_workflows, class_name: 'Sipity::Workflow', dependent: :destroy

    # In a perfect world, there would be a join table that enforced uniqueness on the ID.
    has_one :active_workflow, -> { where(active: true) }, class_name: 'Sipity::Workflow', foreign_key: :permission_template_id

    ##
    # @api public<commit_msg>add some documentation for `PermissionTemplateAccess`<commit_after># frozen_string_literal: true
module Hyrax
  ##
  # Holds policy data about the workflow and permissions applied objects when
  # they are deposited through an Administrative Set or a Collection. Each
  # template record has a {#source} (through {#source_id}); the template's
  # rules inform the behavior of objects deposited through that {#source_model}.
  #
  # The {PermissionTemplate} specifies:
  #
  # - an {#active_workflow} that the object will enter and be processed through.
  # - {#access_grants} that can be applied to each object (especially at deposit
  #   time).
  # - an embargo configuration ({#release_date} {#release_period}) for default
  #   embargo behavior.
  #
  # Additionally, the {PermissionTemplate} grants authority to perform actions
  # that relate to the Administrative Set/Collection itself. Rules for who can
  # deposit to, view(?!), or manage the admin set are governed by related
  # {PermissionTemplateAccess} records. Administrat Sets should have a manager
  # granted by some such record.
  #
  # @todo write up what "default embargo behavior", when it is applied, and how
  #   it interacts with embargoes specified by user input.
  #
  # @example cerating a permission template and manager for an admin set
  #   admin_set = Hyrax::AdministrativeSet.new(title: 'My Admin Set')
  #   admin_set = Hyrax.persister.save(resource: admin_set)
  #
  #   template = PermissionTemplate.create!(source_id: admin_set.id.to_s)
  #   Hyrax::PermissionTemplateAccess.create!(permission_template: template,
  #                                          agent_type: Hyrax::PermissionTemplateAccess::USER,
  #                                          agent_id: user.user_key,
  #                                          access: Hyrax::PermissionTemplateAccess::MANAGE)
  #
  # @see Hyrax::AdministrativeSet
  class PermissionTemplate < ActiveRecord::Base # rubocop:disable Metrics/ClassLength
    self.table_name = 'permission_templates'

    ##
    # @!attribute [rw] source_id
    #   @return [String] identifier for the {Collection} or {AdministrativeSet}
    #     to which this template applies.
    # @!attribute [rw] access_grants
    #   @return [Hyrax::PermissionTemplateAccess]
    # @!attribute [rw] active_workflow
    #   @return [Sipity::Workflow]
    # @!attribute [rw] available_workflows
    #   @return [Enumerable<Sipity::Workflow>]
    has_many :access_grants, class_name: 'Hyrax::PermissionTemplateAccess', dependent: :destroy
    accepts_nested_attributes_for :access_grants, reject_if: :all_blank

    # The list of workflows that could be activated; It includes the active workflow
    has_many :available_workflows, class_name: 'Sipity::Workflow', dependent: :destroy

    # In a perfect world, there would be a join table that enforced uniqueness on the ID.
    has_one :active_workflow, -> { where(active: true) }, class_name: 'Sipity::Workflow', foreign_key: :permission_template_id

    ##
    # @api public
{'fraction_non_alphanumeric': 0.0893069306930693, 'fraction_numerical': 0.0, 'mean_word_length': 3.824259789875836, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2750993', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1381, 'n_words': 471}