File tree 2 files changed +44
-5
lines changed
2 files changed +44
-5
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,33 @@ async def inner():
37
37
return inner
38
38
39
39
40
+ _track_event_seen_actor_ids = set ()
41
+
42
+
43
+ @hookimpl
44
+ def permission_allowed (datasette , actor ):
45
+ actor_id = actor .get ("id" ) if actor else None
46
+ if not actor_id :
47
+ return
48
+ if actor_id in _track_event_seen_actor_ids :
49
+ return
50
+
51
+ async def inner ():
52
+ db = datasette .get_internal_database ()
53
+ # Insert into profiles if it doesn't exist
54
+ await db .execute_write (
55
+ """
56
+ insert into profiles (id)
57
+ values (:id)
58
+ on conflict (id) do nothing
59
+ """ ,
60
+ {"id" : str (actor_id )},
61
+ )
62
+ _track_event_seen_actor_ids .add (actor_id )
63
+
64
+ return inner
65
+
66
+
40
67
# Regular expression to extract base64 data from Data URL
41
68
DATA_URL_RE = re .compile (r"data:image/(jpeg|png|gif|webp);base64,(.*)" )
42
69
Original file line number Diff line number Diff line change 3
3
4
4
5
5
@pytest .mark .asyncio
6
- async def test_plugin_is_installed ():
6
+ async def test_profiles_table_populated_on_visit ():
7
7
datasette = Datasette (memory = True )
8
- response = await datasette .client .get ("/-/plugins.json" )
9
- assert response .status_code == 200
10
- installed_plugins = {p ["name" ] for p in response .json ()}
11
- assert "datasette-profiles" in installed_plugins
8
+ await datasette .invoke_startup ()
9
+ internal_db = datasette .get_internal_database ()
10
+ for actor_id in ("user1" , "user2" ):
11
+ assert not (
12
+ await internal_db .execute (
13
+ "select count(*) from profiles where id = ?" , (actor_id ,)
14
+ )
15
+ ).single_value ()
16
+ await datasette .client .get (
17
+ "/" , cookies = {"ds_actor" : datasette .client .actor_cookie ({"id" : actor_id })}
18
+ )
19
+ assert (
20
+ await internal_db .execute (
21
+ "select count(*) from profiles where id = ?" , (actor_id ,)
22
+ )
23
+ ).single_value () == 1
You can’t perform that action at this time.
0 commit comments