Skip to content

Commit 357e7f6

Browse files
committed
Updated permissions
1 parent 8a2a10f commit 357e7f6

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

.idea/sqldialects.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/macrostrat/cli/database/__init__.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@
44
from typing import Any, Callable, Iterable
55

66
import typer
7-
from pydantic import BaseModel
8-
from rich import print
9-
from sqlalchemy import make_url, text
10-
from typer import Argument, Option
11-
12-
from macrostrat.core import MacrostratSubsystem, app
13-
from macrostrat.core.migrations import run_migrations
147
from macrostrat.database import Database
158
from macrostrat.database.transfer import pg_dump_to_file, pg_restore_from_file
169
from macrostrat.database.transfer.utils import raw_database_url
1710
from macrostrat.database.utils import get_sql_files
1811
from macrostrat.utils import get_logger
1912
from macrostrat.utils.shell import run
13+
from pydantic import BaseModel
14+
from rich import print
15+
from sqlalchemy import make_url, text
16+
from typer import Argument, Option
2017

18+
from macrostrat.core import MacrostratSubsystem, app
19+
from macrostrat.core.migrations import run_migrations
2120
from ._legacy import get_db
22-
2321
# First, register all migrations
2422
# NOTE: right now, this is quite implicit.
2523
from .migrations import load_migrations
@@ -57,7 +55,7 @@ def apply(self, db, match: str = None):
5755
for f in self.fixtures:
5856
if callable(f):
5957
f(db)
60-
return
58+
continue
6159
# This does the same as the upstream "Apply fixtures" function
6260
# but it has support for a 'match' parameter
6361
files = _match_paths(get_sql_files(f), match)

cli/macrostrat/cli/database/utils.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ def get_table_permissions(db, schema, table, user) -> set[Permission]:
181181
return {Permission(p) for p in perms.scalars()}
182182

183183

184-
def grant_permissions(schema, user, *_permissions, owner=False):
184+
def grant_permissions(
185+
schema, user, *_permissions, owner=False, tables: list[str] = None
186+
):
185187
"""Higher-order function to grant permissions on a schema to a user"""
186188

187189
def setup_permissions(db):
@@ -198,10 +200,11 @@ def setup_permissions(db):
198200
f"Grant {_perms} on schema [cyan bold]{schema}[/] to [cyan bold]{user}[/]"
199201
)
200202

201-
tables = db.run_query(
202-
"SELECT table_name FROM information_schema.tables WHERE table_schema = :schema",
203-
dict(schema=schema),
204-
)
203+
if tables is None:
204+
tables = db.run_query(
205+
"SELECT table_name FROM information_schema.tables WHERE table_schema = :schema",
206+
dict(schema=schema),
207+
)
205208
stmts = [
206209
(
207210
"GRANT USAGE ON SCHEMA {schema} TO {user}",

cli/macrostrat/cli/subsystems/xdd/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from rich import print
66
from typer import Typer
77

8+
from ..macrostrat_api import setup_postgrest_access
89
from ...database import SubsystemSchemaDefinition, get_db
910
from ...database.utils import grant_permissions, grant_schema_ownership
10-
from ..macrostrat_api import setup_postgrest_access
1111

1212
__here__ = Path(__file__).parent
1313
fixtures_dir = __here__ / "fixtures"
@@ -19,6 +19,9 @@
1919
fixtures_dir / "kg-views.sql",
2020
setup_postgrest_access("macrostrat_xdd"),
2121
grant_schema_ownership("macrostrat_xdd", "xdd-writer"),
22+
grant_permissions(
23+
"macrostrat_xdd", "web_admin", ["SELECT", "UPDATE"], tables=["source_text"]
24+
),
2225
],
2326
)
2427

cli/macrostrat/cli/subsystems/xdd/fixtures/kg-views.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,5 @@ RETURNS integer AS $$
305305
)
306306
SELECT id FROM next_run;
307307
$$ LANGUAGE SQL;
308+
309+
GRANT web_admin TO "macrostrat_admin";

0 commit comments

Comments
 (0)