Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Datafile bugfix #4157

Merged
merged 7 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mathesar/imports/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
CHECK_ROWS = 10


def import_csv(data_file_id, table_name, schema_oid, conn, comment=None):
data_file = DataFile.objects.get(id=data_file_id)
def import_csv(user, data_file_id, table_name, schema_oid, conn, comment=None):
data_file = DataFile.objects.get(id=data_file_id, user=user)
file_path = data_file.file.path
header = data_file.header
if table_name is None or table_name == '':
Expand Down
2 changes: 1 addition & 1 deletion mathesar/rpc/tables/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def import_(
"""
user = kwargs.get(REQUEST_KEY).user
with connect(database_id, user) as conn:
return import_csv(data_file_id, table_name, schema_oid, conn, comment)
return import_csv(user, data_file_id, table_name, schema_oid, conn, comment)


@mathesar_rpc_method(name="tables.get_import_preview", auth="login")
Expand Down
8 changes: 6 additions & 2 deletions mathesar/tests/rpc/tables/test_t_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,12 @@ def mock_connect(_database_id, user):
else:
raise AssertionError('incorrect parameters passed')

def mock_table_import(_data_file_id, table_name, _schema_oid, conn, comment):
if _schema_oid != schema_oid and _data_file_id != data_file_id:
def mock_table_import(_user, _data_file_id, table_name, _schema_oid, conn, comment):
if (
_user != request.user
and _schema_oid != schema_oid
and _data_file_id != data_file_id
):
raise AssertionError('incorrect parameters passed')
return {"oid": 1964474, "name": "imported_table"}
monkeypatch.setattr(tables.base, 'connect', mock_connect)
Expand Down
Loading