Release 0.1.49: self-hosted maps and consented cloud location history
This commit is contained in:
+26
-4
@@ -1,4 +1,4 @@
|
||||
"""Member-bound location sharing. Pairing is not consent; coordinates are RAM-only."""
|
||||
"""Member-bound sharing. Live fixes stay in RAM; history needs separate consent."""
|
||||
import hashlib
|
||||
import json
|
||||
import math
|
||||
@@ -86,7 +86,7 @@ class Locations:
|
||||
grant=dict(memberId=member['id'],personId=person['id'],memberName=person['name'],familyId=family,
|
||||
home=a.get_object('households',family)['name'],until=now+600,expires=now+days*86400,
|
||||
**chosen,viewOnly=view_only,intervalSeconds=300,createdBy=user['id'],
|
||||
consentProtocol=3 if view_only or chosen['phones'] else 2)
|
||||
historyDefault=True,consentProtocol=3 if view_only or chosen['phones'] else 2)
|
||||
self.refresh_receipt(grant)
|
||||
self.codes[digest]=grant
|
||||
return dict(code=code,validSeconds=600,expires=grant['expires'])
|
||||
@@ -116,6 +116,24 @@ class Locations:
|
||||
return dict(token=token,**{k:grant[k] for k in ('home','memberName','viewers','displays','phones','viewOnly','intervalSeconds','expires','receipt','consentProtocol')})
|
||||
|
||||
def native(self, token, body):
|
||||
if body.get('action') in ('history-list','history-delete'):
|
||||
return self.a.HISTORY.native(token,body)
|
||||
result=self._native(token,body)
|
||||
if body.get('action')=='update' and body.get('position') and body.get('signal')=='available':
|
||||
with self.a.LOCK:
|
||||
row=self.a.DB.execute('SELECT * FROM member_location_shares WHERE token_hash=? AND enabled=1 AND expires>?',(hashlib.sha256(token.encode()).hexdigest(),time.time())).fetchone()
|
||||
if row:
|
||||
fix=self.latest.get(row['id'],{}).get('fix');grant=json.loads(row['grant_json'])
|
||||
if fix and fix['at']==body['position']['at']:
|
||||
self.a.HISTORY.record(row,grant,fix)
|
||||
else:fix=None
|
||||
else:fix=None
|
||||
if fix:
|
||||
try:self.a.MAPS.archive.observe(fix)
|
||||
except Exception:pass # A public map outage cannot break real-time sharing.
|
||||
return result
|
||||
|
||||
def _native(self, token, body):
|
||||
a=self.a;now=time.time()
|
||||
if not isinstance(token,str) or len(token)!=43:raise a.Problem('需要手机配对授权',401)
|
||||
with a.LOCK,a.DB:
|
||||
@@ -135,14 +153,18 @@ class Locations:
|
||||
return dict(viewers=users,displays=displays,phones=[p for p in self.phones(row['family_id']) if p['id']!=sid],
|
||||
viewerIds=[v['id'] for v in grant['viewers']],displayIds=[v['id'] for v in grant['displays']],
|
||||
phoneIds=[v['id'] for v in grant.get('phones',[])],receipt=grant['receipt'],
|
||||
intervalSeconds=grant.get('intervalSeconds',300),viewOnly=grant.get('viewOnly',False))
|
||||
intervalSeconds=grant.get('intervalSeconds',300),viewOnly=grant.get('viewOnly',False),
|
||||
historyEnabled=grant.get('historyEnabled',False),historyDefault=grant.get('historyDefault',False) and 'historyEnabled' not in grant,
|
||||
history=self.a.HISTORY.own_status(row['member_id']))
|
||||
if action=='configure':
|
||||
if body.get('consent') is not True or body.get('receipt')!=grant['receipt']:raise a.Problem('请本人确认新的共享设置',403)
|
||||
chosen=self.select_recipients(row['family_id'],body,own_id=sid)
|
||||
interval=body.get('intervalSeconds',300)
|
||||
if type(interval) is not int or interval not in (10,60,300):raise a.Problem('请选择实时、1 分钟或 5 分钟')
|
||||
if not any(chosen.values()):raise a.Problem('至少选择一位查看人;只查看家人无需开启自己的共享')
|
||||
grant.update(chosen,viewOnly=False,intervalSeconds=interval,consentProtocol=3)
|
||||
history=body.get('historyEnabled',False)
|
||||
if type(history) is not bool or history and body.get('historyConsent') is not True:raise a.Problem('长期保存轨迹需要本人单独同意',403)
|
||||
grant.update(chosen,viewOnly=False,intervalSeconds=interval,consentProtocol=3,historyEnabled=history)
|
||||
self.refresh_receipt(grant)
|
||||
a.DB.execute('UPDATE member_location_shares SET enabled=0,grant_json=? WHERE id=?',(json.dumps(grant),sid))
|
||||
self.latest.pop(sid,None)
|
||||
|
||||
Reference in New Issue
Block a user