describing a custom location should honor access restrictions
This commit is contained in:
parent
85beff40e7
commit
e5055856fe
3 changed files with 19 additions and 12 deletions
|
@ -270,7 +270,8 @@ def get_position_by_id(request, position_id: AnyPositionID):
|
||||||
location = Position.objects.get(secret=position_id[2:])
|
location = Position.objects.get(secret=position_id[2:])
|
||||||
except Position.DoesNotExist:
|
except Position.DoesNotExist:
|
||||||
raise API404()
|
raise API404()
|
||||||
return location.serialize_position()
|
|
||||||
|
return location.serialize_position(request=request)
|
||||||
|
|
||||||
|
|
||||||
class UpdatePositionSchema(BaseSchema):
|
class UpdatePositionSchema(BaseSchema):
|
||||||
|
@ -314,7 +315,7 @@ def set_position(request, position_id: AnyPositionID, update: UpdatePositionSche
|
||||||
location.last_coordinates_update = timezone.now()
|
location.last_coordinates_update = timezone.now()
|
||||||
location.save()
|
location.save()
|
||||||
|
|
||||||
return location.serialize_position()
|
return location.serialize_position(request=request)
|
||||||
|
|
||||||
|
|
||||||
@map_api_router.get('/projection/', summary='get proj4 string',
|
@map_api_router.get('/projection/', summary='get proj4 string',
|
||||||
|
|
|
@ -515,7 +515,9 @@ class LabelSettings(SerializableMixin, models.Model):
|
||||||
|
|
||||||
|
|
||||||
class CustomLocationProxyMixin:
|
class CustomLocationProxyMixin:
|
||||||
def get_custom_location(self):
|
request = None
|
||||||
|
|
||||||
|
def get_custom_location(self, request=None):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -534,7 +536,7 @@ class CustomLocationProxyMixin:
|
||||||
def level(self):
|
def level(self):
|
||||||
return self.get_custom_location().level
|
return self.get_custom_location().level
|
||||||
|
|
||||||
def serialize_position(self):
|
def serialize_position(self, request=None):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
@ -560,8 +562,8 @@ class DynamicLocation(CustomLocationProxyMixin, SpecificLocation, models.Model):
|
||||||
def register_change(self, force=False):
|
def register_change(self, force=False):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def serialize_position(self):
|
def serialize_position(self, request=None):
|
||||||
custom_location = self.get_custom_location()
|
custom_location = self.get_custom_location(request=request)
|
||||||
if custom_location is None:
|
if custom_location is None:
|
||||||
return {
|
return {
|
||||||
'available': False,
|
'available': False,
|
||||||
|
@ -587,11 +589,13 @@ class DynamicLocation(CustomLocationProxyMixin, SpecificLocation, models.Model):
|
||||||
})
|
})
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_custom_location(self):
|
def get_custom_location(self, request=None):
|
||||||
if not self.position_secret:
|
if not self.position_secret:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
return Position.objects.get(secret=self.position_secret).get_custom_location()
|
return Position.objects.get(secret=self.position_secret).get_custom_location(
|
||||||
|
requests=request if request is not None else self.request
|
||||||
|
)
|
||||||
except Position.DoesNotExist:
|
except Position.DoesNotExist:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -633,7 +637,9 @@ class Position(CustomLocationProxyMixin, models.Model):
|
||||||
self.coordinates = None
|
self.coordinates = None
|
||||||
self.last_coordinates_update = end_time
|
self.last_coordinates_update = end_time
|
||||||
|
|
||||||
def get_custom_location(self):
|
def get_custom_location(self, request=None):
|
||||||
|
if request is not None:
|
||||||
|
self.request = request # todo: this is ugly, yes
|
||||||
return self.coordinates
|
return self.coordinates
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -647,8 +653,8 @@ class Position(CustomLocationProxyMixin, models.Model):
|
||||||
cache.set(cache_key, result, 600)
|
cache.set(cache_key, result, 600)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def serialize_position(self):
|
def serialize_position(self, request=None):
|
||||||
custom_location = self.get_custom_location()
|
custom_location = self.get_custom_location(request=request)
|
||||||
if custom_location is None:
|
if custom_location is None:
|
||||||
return {
|
return {
|
||||||
'id': 'p:%s' % self.secret,
|
'id': 'p:%s' % self.secret,
|
||||||
|
|
|
@ -169,7 +169,7 @@ def preview_location(request, slug):
|
||||||
geometries = [loc.geometry for loc in location.locations if loc.level_id == level]
|
geometries = [loc.geometry for loc in location.locations if loc.level_id == level]
|
||||||
highlight = True
|
highlight = True
|
||||||
elif isinstance(location, Position):
|
elif isinstance(location, Position):
|
||||||
loc = location.get_custom_location()
|
loc = location.get_custom_location(request=request)
|
||||||
if not loc:
|
if not loc:
|
||||||
raise Http404
|
raise Http404
|
||||||
geometries = [Point(loc.x, loc.y)]
|
geometries = [Point(loc.x, loc.y)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue