<commit_before>module Sufia
  module GenericFile
    module Visibility
      extend ActiveSupport::Concern
      extend Deprecation

      def visibility=(value)
        return if value.nil?
        # only set explicit permissions
        case value
        when Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
          public_visibility!
        when Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
          registered_visibility!
        when Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
          private_visibility!
        else
          raise ArgumentError, "Invalid visibility: #{value.inspect}"
        end
      end

      def visibility
        if read_groups.include? Sufia::Models::AccessRight::PERMISSION_TEXT_VALUE_PUBLIC
          Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
        elsif read_groups.include? Sufia::Models::AccessRight::PERMISSION_TEXT_VALUE_AUTHENTICATED
          Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
        else
          Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
        end
      end

      def set_visibility(visibility)
        Deprecation.warn Visibility, "set_visibility is deprecated, use visibility= instead.  set_visibility will be removed in sufia 3.0", caller
        self.visibility= visibility
      end

      private
      def visibility_will_change!
        @visibility_will_change = true
      end
      def visibility_changed?
        @visibility_will_change
      end

      def public_visibility!
        visibility_will_change! unless visibility == Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
        self.datastreams["rightsMetadata"].permissions({:group=>Sufia::Models::AccessRight::PERMISSION_TEXT_VALUE_PUBLIC}, "read")
      end

      def registered_visibility!
        visibility_will_change! unless visibility == Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
        self.datastreams["rightsMetadata"].permissions({:group=>Sufia::Models::AccessRight::PERMISSION_TEXT_VALUE_AUTHENTICATED}, "read")
        self.datastreams["rightsMetadata"].permissions({:group=>Sufia::Models::AccessRight::PERMISSION_TEXT_VALUE_PUBLIC}, "none")
      end

      def private_visibility!
        visibility_will_change! unless visibility == Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
        self.datastreams["rightsMetadata"].permissions({:group=>Sufia::Models::AccessRight::PERMISSION_TEXT_VALUE_AUTHENTICATED}, "none")
        self.datastreams["rightsMetadata"].permissions({:group=>Sufia::Models::AccessRight::PERMISSION_TEXT_VALUE_PUBLIC}, "none")
      end
<commit_msg>Publicizing #visibility_changed?<commit_after>module Sufia
  module GenericFile
    module Visibility
      extend ActiveSupport::Concern
      extend Deprecation

      def visibility=(value)
        return if value.nil?
        # only set explicit permissions
        case value
        when Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
          public_visibility!
        when Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
          registered_visibility!
        when Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
          private_visibility!
        else
          raise ArgumentError, "Invalid visibility: #{value.inspect}"
        end
      end

      def visibility
        if read_groups.include? Sufia::Models::AccessRight::PERMISSION_TEXT_VALUE_PUBLIC
          Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
        elsif read_groups.include? Sufia::Models::AccessRight::PERMISSION_TEXT_VALUE_AUTHENTICATED
          Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
        else
          Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
        end
      end

      def set_visibility(visibility)
        Deprecation.warn Visibility, "set_visibility is deprecated, use visibility= instead.  set_visibility will be removed in sufia 3.0", caller
        self.visibility= visibility
      end

      def visibility_changed?
        @visibility_will_change
      end

      private
      def visibility_will_change!
        @visibility_will_change = true
      end

      def public_visibility!
        visibility_will_change! unless visibility == Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
        self.datastreams["rightsMetadata"].permissions({:group=>Sufia::Models::AccessRight::PERMISSION_TEXT_VALUE_PUBLIC}, "read")
      end

      def registered_visibility!
        visibility_will_change! unless visibility == Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
        self.datastreams["rightsMetadata"].permissions({:group=>Sufia::Models::AccessRight::PERMISSION_TEXT_VALUE_AUTHENTICATED}, "read")
        self.datastreams["rightsMetadata"].permissions({:group=>Sufia::Models::AccessRight::PERMISSION_TEXT_VALUE_PUBLIC}, "none")
      end

      def private_visibility!
        visibility_will_change! unless visibility == Sufia::Models::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
        self.datastreams["rightsMetadata"].permissions({:group=>Sufia::Models::AccessRight::PERMISSION_TEXT_VALUE_AUTHENTICATED}, "none")
        self.datastreams["rightsMetadata"].permissions({:group=>Sufia::Models::AccessRight::PERMISSION_TEXT_VALUE_PUBLIC}, "none")
      end

{'fraction_non_alphanumeric': 0.08713537771129394, 'fraction_numerical': 0.0007479431563201197, 'mean_word_length': 4.0605487228003785, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6813018', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1460, 'n_words': 229}