Skip to content

Commit

Permalink
Merge pull request #256 from MAPC/develop
Browse files Browse the repository at this point in the history
Version 1.0.9
  • Loading branch information
iangmhill authored Aug 13, 2018
2 parents 414abe4 + e9d5648 commit 0c96ef9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rails/app/models/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def geocode
if result && JSON.parse(result.body)['features'].length > 0
properties = JSON.parse(result.body)['features'][0]['properties']
self.update_columns(
municipal: properties['locality'],
municipal: (properties['locality'] || properties['localadmin']),
address: properties['name'],
zip_code: properties['postalcode']
)
Expand Down
13 changes: 12 additions & 1 deletion rails/app/policies/development_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def show?
end

def create?
!user&.disabled? && (user&.admin? || user&.verified? || (user&.municipal? && (record.municipal == user.municipality)))
!user&.disabled? && (user&.admin? || user&.verified? || (user&.municipal? && (record.municipal == user.municipality || get_municipality(record) == user.municipality)))
end

def update?
Expand All @@ -22,4 +22,15 @@ def update?
def destroy?
!user&.disabled? && (user&.admin? || (user&.municipal? && (record.municipal == user.municipality)))
end

private

def get_municipality(record)
result = Faraday.get "https://pelias.mapc.org/v1/reverse?point.lat=#{record.latitude}&point.lon=#{record.longitude}"
if result && JSON.parse(result.body)['features'].length > 0
properties = JSON.parse(result.body)['features'][0]['properties']
return (properties['locality'] || properties['localadmin'])
end
end

end

0 comments on commit 0c96ef9

Please sign in to comment.