aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/concerns/objectid_restrictions.rb
diff options
context:
space:
mode:
authorXinhui2016-02-22 15:31:31 +0100
committerXinhui2016-02-22 15:31:31 +0100
commit0a1ffa22d97160797d2c96debbc99b31792a40c5 (patch)
tree7cea5119ddf42cbfe8d1e52c6d28096979830cd4 /app/models/concerns/objectid_restrictions.rb
parentd49f47b4ac1db2cd88b96d830772bb7773924601 (diff)
downloadchouette-core-0a1ffa22d97160797d2c96debbc99b31792a40c5.tar.bz2
Merge NinoxeExtension concerns
Diffstat (limited to 'app/models/concerns/objectid_restrictions.rb')
-rw-r--r--app/models/concerns/objectid_restrictions.rb28
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
+