Skip to content

Commit

Permalink
feat: update dataset sort
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouhaoJiang committed Jul 7, 2024
1 parent b27f4ac commit f98ebf2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion api/controllers/console/datasets/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,12 @@ def patch(self, dataset_id):
raise NotFound("Dataset not found.")

result_data = marshal(dataset, dataset_detail_fields)
tenant_id = current_user.current_tenant_id

if data.get('partial_member_list') and data.get('permission') == 'partial_members':
DatasetPermissionService.update_partial_member_list(dataset_id_str, data.get('partial_member_list'))
DatasetPermissionService.update_partial_member_list(
tenant_id, dataset_id_str, data.get('partial_member_list')
)
else:
DatasetPermissionService.clear_partial_member_list(dataset_id_str)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('dataset_permissions', schema=None) as batch_op:
# batch_op.add_column(sa.Column('tenant_id', models.StringUUID(), nullable=False))
# Step 1: Add column without NOT NULL constraint
op.add_column('dataset_permissions', sa.Column('tenant_id', sa.UUID(), nullable=True))

Expand Down
4 changes: 3 additions & 1 deletion api/models/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,11 +670,13 @@ class DatasetPermission(db.Model):
__table_args__ = (
db.PrimaryKeyConstraint('id', name='dataset_permission_pkey'),
db.Index('idx_dataset_permissions_dataset_id', 'dataset_id'),
db.Index('idx_dataset_permissions_account_id', 'account_id')
db.Index('idx_dataset_permissions_account_id', 'account_id'),
db.Index('idx_dataset_permissions_tenant_id', 'tenant_id')
)

id = db.Column(StringUUID, server_default=db.text('uuid_generate_v4()'), primary_key=True)
dataset_id = db.Column(StringUUID, nullable=False)
account_id = db.Column(StringUUID, nullable=False)
tenant_id = db.Column(StringUUID, nullable=False)
has_permission = db.Column(db.Boolean, nullable=False, server_default=db.text('true'))
created_at = db.Column(db.DateTime, nullable=False, server_default=db.text('CURRENT_TIMESTAMP(0)'))
9 changes: 7 additions & 2 deletions api/services/dataset_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ def get_datasets(page, per_page, provider="vendor", tenant_id=None, user=None, s

if user:
if user.current_role == TenantAccountRole.DATASET_OPERATOR:
dataset_permission = DatasetPermission.query.filter_by(account_id=user.id).all()
dataset_permission = DatasetPermission.query.filter_by(
account_id=user.id,
tenant_id=tenant_id
).all()
if dataset_permission:
dataset_ids = [dp.dataset_id for dp in dataset_permission]
query = query.filter(Dataset.id.in_(dataset_ids))
Expand Down Expand Up @@ -354,6 +357,7 @@ def filter_datasets_by_permission(user, datasets):
(dataset.id in permitted_dataset_ids)
]

filtered_datasets.sort(key=lambda x: x.created_at, reverse=True)
filtered_count = len(filtered_datasets)

return filtered_datasets, filtered_count
Expand Down Expand Up @@ -1586,12 +1590,13 @@ def get_dataset_partial_member_list(cls, dataset_id):
return user_list

@classmethod
def update_partial_member_list(cls, dataset_id, user_list):
def update_partial_member_list(cls, tenant_id, dataset_id, user_list):
try:
db.session.query(DatasetPermission).filter(DatasetPermission.dataset_id == dataset_id).delete()
permissions = []
for user in user_list:
permission = DatasetPermission(
tenant_id=tenant_id,
dataset_id=dataset_id,
account_id=user['user_id'],
)
Expand Down

0 comments on commit f98ebf2

Please sign in to comment.