add permission service, add validations to map.rb
This commit is contained in:
parent
b3ba6d3a80
commit
bfd4e4f228
2 changed files with 40 additions and 7 deletions
|
@ -13,6 +13,9 @@ class Map < ActiveRecord::Base
|
||||||
#:full => ['940x630#', :png]
|
#:full => ['940x630#', :png]
|
||||||
},
|
},
|
||||||
:default_url => 'https://s3.amazonaws.com/metamaps-assets/site/missing-map.png'
|
:default_url => 'https://s3.amazonaws.com/metamaps-assets/site/missing-map.png'
|
||||||
|
validates_presence_of :name
|
||||||
|
validates_presence_of :arranged
|
||||||
|
validate_presence_of :permission
|
||||||
|
|
||||||
# Validate the attached image is image/jpg, image/png, etc
|
# Validate the attached image is image/jpg, image/png, etc
|
||||||
validates_attachment_content_type :screenshot, :content_type => /\Aimage\/.*\Z/
|
validates_attachment_content_type :screenshot, :content_type => /\Aimage\/.*\Z/
|
||||||
|
@ -22,13 +25,7 @@ class Map < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def mk_permission
|
def mk_permission
|
||||||
if self.permission == "commons"
|
Perm.short(permission)
|
||||||
"co"
|
|
||||||
elsif self.permission == "public"
|
|
||||||
"pu"
|
|
||||||
elsif self.permission == "private"
|
|
||||||
"pr"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#return an array of the contributors to the map
|
#return an array of the contributors to the map
|
||||||
|
|
36
app/services/perm.rb
Normal file
36
app/services/perm.rb
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
class Perm
|
||||||
|
class << self
|
||||||
|
# e.g. Perm::ISSIONS
|
||||||
|
ISSIONS = [:commons, :public, :private]
|
||||||
|
|
||||||
|
def short(permission)
|
||||||
|
case permission
|
||||||
|
when :commons
|
||||||
|
"co"
|
||||||
|
when :public
|
||||||
|
"pu"
|
||||||
|
when :private
|
||||||
|
"pr"
|
||||||
|
else
|
||||||
|
fail "Invalid permission"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def long(perm)
|
||||||
|
case perm
|
||||||
|
when "co"
|
||||||
|
:commons
|
||||||
|
when "pu"
|
||||||
|
:public
|
||||||
|
when "pr"
|
||||||
|
:private
|
||||||
|
else
|
||||||
|
fail "Invalid short permission"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid?(permission)
|
||||||
|
ISSIONS.include? permission
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue