diff options
Diffstat (limited to 'app/models/concerns/objectid_restrictions.rb')
| -rw-r--r-- | app/models/concerns/objectid_restrictions.rb | 28 | 
1 files changed, 28 insertions, 0 deletions
| diff --git a/app/models/concerns/objectid_restrictions.rb b/app/models/concerns/objectid_restrictions.rb new file mode 100644 index 000000000..4e905bdc2 --- /dev/null +++ b/app/models/concerns/objectid_restrictions.rb @@ -0,0 +1,28 @@ +module ObjectidRestrictions +    extend ActiveSupport::Concern + +    included do +      # HUB 1 +      validate :third_part_objectid_uniqueness +    end + +    def validate_specific_objectid( size_max ) +      #errors.add( :objectid, I18n.t('hub.invalid')) if ( %r{\A\w+:\w+:\w+\z}).match( self.objectid).nil? + +      if third_part_objectid.nil? || ( !third_part_objectid.include?( "_pending_" ) && third_part_objectid.size > size_max) +        errors.add( :objectid, I18n.t('hub.invalid')) +      end +    end +    def third_part_objectid +      return nil if ( %r{\A\w+:\w+:[0-9A-Za-z_-]+\z}).match( self.objectid).nil? +      self.objectid.match(/:([0-9A-Za-z_-]+)\z/)[1] +    end +    def third_part_objectid_uniqueness +      return unless hub_restricted? + +      return true unless third_part_objectid +      likes = self.class.where( "objectid LIKE ?", "%:#{self.third_part_objectid}" ) +      likes.size.zero? || ( likes.size==1 && likes.first.id==self.id) +    end +end + | 
