Skip to content

Commit

Permalink
return DatabaseInfo if transferring ownership succeeds
Browse files Browse the repository at this point in the history
  • Loading branch information
Anish9901 committed Sep 12, 2024
1 parent ce7171f commit 0134697
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion db/roles/operations/ownership.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def transfer_database_ownership(new_owner_oid, conn):
exec_msar_func(conn, 'transfer_database_ownership', new_owner_oid)
return exec_msar_func(conn, 'transfer_database_ownership', new_owner_oid).fetchone()[0]
4 changes: 3 additions & 1 deletion db/sql/00_msar.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1434,8 +1434,9 @@ END;
$$ LANGUAGE plpgsql RETURNS NULL ON NULL INPUT;


DROP FUNCTION IF EXISTS msar.transfer_database_ownership(regrole);
CREATE OR REPLACE FUNCTION
msar.transfer_database_ownership(new_owner_oid regrole) RETURNS void AS $$/*
msar.transfer_database_ownership(new_owner_oid regrole) RETURNS jsonb AS $$/*
Transfers ownership of the current database to a new owner.
Args:
Expand All @@ -1453,6 +1454,7 @@ BEGIN
pg_catalog.current_database(),
msar.get_role_name(new_owner_oid)
);
RETURN msar.get_current_database_info();
END;
$$ LANGUAGE plpgsql RETURNS NULL ON NULL INPUT;

Expand Down
9 changes: 7 additions & 2 deletions mathesar/rpc/databases/privileges.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from db.roles.operations.select import list_db_priv
from db.roles.operations.update import replace_database_privileges_for_roles
from db.roles.operations.ownership import transfer_database_ownership
from mathesar.rpc.databases.base import DatabaseInfo
from mathesar.rpc.utils import connect
from mathesar.rpc.exceptions.handlers import handle_rpc_exceptions

Expand Down Expand Up @@ -84,7 +85,7 @@ def replace_for_roles(
@rpc_method(name="databases.privileges.transfer_ownership")
@http_basic_auth_login_required
@handle_rpc_exceptions
def transfer_ownership(*, new_owner_oid: int, database_id: int, **kwargs) -> None:
def transfer_ownership(*, new_owner_oid: int, database_id: int, **kwargs) -> DatabaseInfo:
"""
Transfers ownership of the current database to a new owner.
Expand All @@ -97,7 +98,11 @@ def transfer_ownership(*, new_owner_oid: int, database_id: int, **kwargs) -> Non
- Be a `MEMBER` of the new owning role. i.e. The current role should be able to `SET ROLE`
to the new owning role.
- Have `CREATEDB` privilege.
Returns:
Information about the database, and the current user privileges.
"""
user = kwargs.get(REQUEST_KEY).user
with connect(database_id, user) as conn:
transfer_database_ownership(new_owner_oid, conn)
db_info = transfer_database_ownership(new_owner_oid, conn)
return DatabaseInfo.from_dict(db_info)

0 comments on commit 0134697

Please sign in to comment.