{"id":15724445,"url":"https://github.com/cldellow/datasette-current-actor","last_synced_at":"2025-03-31T01:14:40.715Z","repository":{"id":65693983,"uuid":"597528620","full_name":"cldellow/datasette-current-actor","owner":"cldellow","description":"Adds a `current_actor()` function to SQLite","archived":false,"fork":false,"pushed_at":"2023-02-12T18:35:12.000Z","size":21,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T12:13:20.915Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cldellow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-04T20:29:38.000Z","updated_at":"2023-02-04T20:52:14.000Z","dependencies_parsed_at":"2023-02-19T14:45:58.733Z","dependency_job_id":null,"html_url":"https://github.com/cldellow/datasette-current-actor","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"b27792d793200029139fe914b3db13ba2888df99"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cldellow%2Fdatasette-current-actor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cldellow%2Fdatasette-current-actor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cldellow%2Fdatasette-current-actor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cldellow%2Fdatasette-current-actor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cldellow","download_url":"https://codeload.github.com/cldellow/datasette-current-actor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246399798,"owners_count":20770908,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T22:16:42.719Z","updated_at":"2025-03-31T01:14:40.685Z","avatar_url":"https://github.com/cldellow.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# datasette-current-actor\n\n[![PyPI](https://img.shields.io/pypi/v/datasette-current-actor.svg)](https://pypi.org/project/datasette-current-actor/)\n[![Changelog](https://img.shields.io/github/v/release/cldellow/datasette-current-actor?include_prereleases\u0026label=changelog)](https://github.com/cldellow/datasette-current-actor/releases)\n[![Tests](https://github.com/cldellow/datasette-current-actor/workflows/Test/badge.svg)](https://github.com/cldellow/datasette-current-actor/actions?query=workflow%3ATest)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/cldellow/datasette-current-actor/blob/main/LICENSE)\n\nAdds functions to SQLite to show the current actor's ID, IP and user agent.\n\n## Installation\n\nInstall this plugin in the same environment as Datasette.\n\n    datasette install datasette-current-actor\n\n## Usage\n\n- `current_actor()` returns the current actor's ID, or `NULL` if no actor.\n- `current_actor('attrs', 'name')` navigates the actor object, returning\n   the value of the `name` key stored in the `attrs` key, or `NULL` if any\n   of the intermediate values are absent.\n- `current_actor_ip()` returns the current actor's IP address\n- `current_actor_user_agent()` returns the current actor's HTTP user agent\n\n### Default values, views and triggers\n\nSQLite is _flexible_. It turns out you can refer to functions that don't exist\nwhen issuing DDL statements. As long as they exist when they're needed, it all\nworks out.\n\n#### Auditing\n\nTrack who added a row:\n\n```sql\nCREATE TABLE notes(\n  created_by text not null default (current_actor()),\n  created_by_ip text not null default (current_actor_ip()),\n  note text not null\n);\n```\n\nOr create an UPDATE trigger on a table that sets the `last_edited_by` column to\n`current_actor()`.\n\n#### Row-level security\n\nRestrict the rows that users see:\n\n```sql\nCREATE VIEW rls AS\nSELECT * FROM sensitive_data WHERE owner = current_actor()\n```\n\nYou can see a live example at https://dux.fly.dev/cooking/my_questions, which should show you 0 rows.\n\nYou can use the hamburger menu in the top right to log in with GitHub. You will then see questions whose owner_id ends\nin the same digit as your GitHub user ID.\n\n\n## Development\n\nTo set up this plugin locally, first checkout the code. Then create a new virtual environment:\n\n    cd datasette-current-actor\n    python3 -m venv venv\n    source venv/bin/activate\n\nNow install the dependencies and test dependencies:\n\n    pip install -e '.[test]'\n\nTo run the tests:\n\n    pytest\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcldellow%2Fdatasette-current-actor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcldellow%2Fdatasette-current-actor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcldellow%2Fdatasette-current-actor/lists"}