Unverified Commit 82882224 authored by crazywoola's avatar crazywoola Committed by GitHub

fix: multiple rows were found correctly (#2219)

parent 2068ae21
...@@ -61,9 +61,7 @@ class BaseApiKeyListResource(Resource): ...@@ -61,9 +61,7 @@ class BaseApiKeyListResource(Resource):
resource_id = str(resource_id) resource_id = str(resource_id)
_get_resource(resource_id, current_user.current_tenant_id, _get_resource(resource_id, current_user.current_tenant_id,
self.resource_model) self.resource_model)
if not current_user.is_admin_or_owner:
# The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']:
raise Forbidden() raise Forbidden()
current_key_count = db.session.query(ApiToken). \ current_key_count = db.session.query(ApiToken). \
...@@ -102,7 +100,7 @@ class BaseApiKeyResource(Resource): ...@@ -102,7 +100,7 @@ class BaseApiKeyResource(Resource):
self.resource_model) self.resource_model)
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
key = db.session.query(ApiToken). \ key = db.session.query(ApiToken). \
......
...@@ -21,7 +21,7 @@ class AnnotationReplyActionApi(Resource): ...@@ -21,7 +21,7 @@ class AnnotationReplyActionApi(Resource):
@cloud_edition_billing_resource_check('annotation') @cloud_edition_billing_resource_check('annotation')
def post(self, app_id, action): def post(self, app_id, action):
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
app_id = str(app_id) app_id = str(app_id)
...@@ -45,7 +45,7 @@ class AppAnnotationSettingDetailApi(Resource): ...@@ -45,7 +45,7 @@ class AppAnnotationSettingDetailApi(Resource):
@account_initialization_required @account_initialization_required
def get(self, app_id): def get(self, app_id):
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
app_id = str(app_id) app_id = str(app_id)
...@@ -59,7 +59,7 @@ class AppAnnotationSettingUpdateApi(Resource): ...@@ -59,7 +59,7 @@ class AppAnnotationSettingUpdateApi(Resource):
@account_initialization_required @account_initialization_required
def post(self, app_id, annotation_setting_id): def post(self, app_id, annotation_setting_id):
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
app_id = str(app_id) app_id = str(app_id)
...@@ -80,7 +80,7 @@ class AnnotationReplyActionStatusApi(Resource): ...@@ -80,7 +80,7 @@ class AnnotationReplyActionStatusApi(Resource):
@cloud_edition_billing_resource_check('annotation') @cloud_edition_billing_resource_check('annotation')
def get(self, app_id, job_id, action): def get(self, app_id, job_id, action):
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
job_id = str(job_id) job_id = str(job_id)
...@@ -108,7 +108,7 @@ class AnnotationListApi(Resource): ...@@ -108,7 +108,7 @@ class AnnotationListApi(Resource):
@account_initialization_required @account_initialization_required
def get(self, app_id): def get(self, app_id):
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
page = request.args.get('page', default=1, type=int) page = request.args.get('page', default=1, type=int)
...@@ -133,7 +133,7 @@ class AnnotationExportApi(Resource): ...@@ -133,7 +133,7 @@ class AnnotationExportApi(Resource):
@account_initialization_required @account_initialization_required
def get(self, app_id): def get(self, app_id):
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
app_id = str(app_id) app_id = str(app_id)
...@@ -152,7 +152,7 @@ class AnnotationCreateApi(Resource): ...@@ -152,7 +152,7 @@ class AnnotationCreateApi(Resource):
@marshal_with(annotation_fields) @marshal_with(annotation_fields)
def post(self, app_id): def post(self, app_id):
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
app_id = str(app_id) app_id = str(app_id)
...@@ -172,7 +172,7 @@ class AnnotationUpdateDeleteApi(Resource): ...@@ -172,7 +172,7 @@ class AnnotationUpdateDeleteApi(Resource):
@marshal_with(annotation_fields) @marshal_with(annotation_fields)
def post(self, app_id, annotation_id): def post(self, app_id, annotation_id):
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
app_id = str(app_id) app_id = str(app_id)
...@@ -189,7 +189,7 @@ class AnnotationUpdateDeleteApi(Resource): ...@@ -189,7 +189,7 @@ class AnnotationUpdateDeleteApi(Resource):
@account_initialization_required @account_initialization_required
def delete(self, app_id, annotation_id): def delete(self, app_id, annotation_id):
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
app_id = str(app_id) app_id = str(app_id)
...@@ -205,7 +205,7 @@ class AnnotationBatchImportApi(Resource): ...@@ -205,7 +205,7 @@ class AnnotationBatchImportApi(Resource):
@cloud_edition_billing_resource_check('annotation') @cloud_edition_billing_resource_check('annotation')
def post(self, app_id): def post(self, app_id):
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
app_id = str(app_id) app_id = str(app_id)
...@@ -230,7 +230,7 @@ class AnnotationBatchImportStatusApi(Resource): ...@@ -230,7 +230,7 @@ class AnnotationBatchImportStatusApi(Resource):
@cloud_edition_billing_resource_check('annotation') @cloud_edition_billing_resource_check('annotation')
def get(self, app_id, job_id): def get(self, app_id, job_id):
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
job_id = str(job_id) job_id = str(job_id)
...@@ -257,7 +257,7 @@ class AnnotationHitHistoryListApi(Resource): ...@@ -257,7 +257,7 @@ class AnnotationHitHistoryListApi(Resource):
@account_initialization_required @account_initialization_required
def get(self, app_id, annotation_id): def get(self, app_id, annotation_id):
# The role of the current user in the table must be admin or owner # The role of the current user in the table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
page = request.args.get('page', default=1, type=int) page = request.args.get('page', default=1, type=int)
......
...@@ -88,7 +88,7 @@ class AppListApi(Resource): ...@@ -88,7 +88,7 @@ class AppListApi(Resource):
args = parser.parse_args() args = parser.parse_args()
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
try: try:
...@@ -237,7 +237,7 @@ class AppApi(Resource): ...@@ -237,7 +237,7 @@ class AppApi(Resource):
"""Delete app""" """Delete app"""
app_id = str(app_id) app_id = str(app_id)
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
app = _get_app(app_id, current_user.current_tenant_id) app = _get_app(app_id, current_user.current_tenant_id)
......
...@@ -157,7 +157,7 @@ class MessageAnnotationApi(Resource): ...@@ -157,7 +157,7 @@ class MessageAnnotationApi(Resource):
@marshal_with(annotation_fields) @marshal_with(annotation_fields)
def post(self, app_id): def post(self, app_id):
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
app_id = str(app_id) app_id = str(app_id)
......
...@@ -42,7 +42,7 @@ class AppSite(Resource): ...@@ -42,7 +42,7 @@ class AppSite(Resource):
app_model = _get_app(app_id) app_model = _get_app(app_id)
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
site = db.session.query(Site). \ site = db.session.query(Site). \
...@@ -88,7 +88,7 @@ class AppSiteAccessTokenReset(Resource): ...@@ -88,7 +88,7 @@ class AppSiteAccessTokenReset(Resource):
app_model = _get_app(app_id) app_model = _get_app(app_id)
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
site = db.session.query(Site).filter(Site.app_id == app_model.id).first() site = db.session.query(Site).filter(Site.app_id == app_model.id).first()
......
...@@ -30,7 +30,7 @@ def get_oauth_providers(): ...@@ -30,7 +30,7 @@ def get_oauth_providers():
class OAuthDataSource(Resource): class OAuthDataSource(Resource):
def get(self, provider: str): def get(self, provider: str):
# The role of the current user in the table must be admin or owner # The role of the current user in the table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
OAUTH_DATASOURCE_PROVIDERS = get_oauth_providers() OAUTH_DATASOURCE_PROVIDERS = get_oauth_providers()
with current_app.app_context(): with current_app.app_context():
......
...@@ -103,7 +103,7 @@ class DatasetListApi(Resource): ...@@ -103,7 +103,7 @@ class DatasetListApi(Resource):
args = parser.parse_args() args = parser.parse_args()
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
try: try:
...@@ -187,7 +187,7 @@ class DatasetApi(Resource): ...@@ -187,7 +187,7 @@ class DatasetApi(Resource):
args = parser.parse_args() args = parser.parse_args()
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
dataset = DatasetService.update_dataset( dataset = DatasetService.update_dataset(
...@@ -205,7 +205,7 @@ class DatasetApi(Resource): ...@@ -205,7 +205,7 @@ class DatasetApi(Resource):
dataset_id_str = str(dataset_id) dataset_id_str = str(dataset_id)
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
if DatasetService.delete_dataset(dataset_id_str, current_user): if DatasetService.delete_dataset(dataset_id_str, current_user):
...@@ -391,7 +391,7 @@ class DatasetApiKeyApi(Resource): ...@@ -391,7 +391,7 @@ class DatasetApiKeyApi(Resource):
@marshal_with(api_key_fields) @marshal_with(api_key_fields)
def post(self): def post(self):
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
current_key_count = db.session.query(ApiToken). \ current_key_count = db.session.query(ApiToken). \
...@@ -425,7 +425,7 @@ class DatasetApiDeleteApi(Resource): ...@@ -425,7 +425,7 @@ class DatasetApiDeleteApi(Resource):
api_key_id = str(api_key_id) api_key_id = str(api_key_id)
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
key = db.session.query(ApiToken). \ key = db.session.query(ApiToken). \
......
...@@ -204,7 +204,7 @@ class DatasetDocumentListApi(Resource): ...@@ -204,7 +204,7 @@ class DatasetDocumentListApi(Resource):
raise NotFound('Dataset not found.') raise NotFound('Dataset not found.')
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
try: try:
...@@ -256,7 +256,7 @@ class DatasetInitApi(Resource): ...@@ -256,7 +256,7 @@ class DatasetInitApi(Resource):
@cloud_edition_billing_resource_check('vector_space') @cloud_edition_billing_resource_check('vector_space')
def post(self): def post(self):
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
parser = reqparse.RequestParser() parser = reqparse.RequestParser()
...@@ -599,7 +599,7 @@ class DocumentProcessingApi(DocumentResource): ...@@ -599,7 +599,7 @@ class DocumentProcessingApi(DocumentResource):
document = self.get_document(dataset_id, document_id) document = self.get_document(dataset_id, document_id)
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
if action == "pause": if action == "pause":
...@@ -663,7 +663,7 @@ class DocumentMetadataApi(DocumentResource): ...@@ -663,7 +663,7 @@ class DocumentMetadataApi(DocumentResource):
doc_metadata = req_data.get('doc_metadata') doc_metadata = req_data.get('doc_metadata')
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
if doc_type is None or doc_metadata is None: if doc_type is None or doc_metadata is None:
...@@ -710,7 +710,7 @@ class DocumentStatusApi(DocumentResource): ...@@ -710,7 +710,7 @@ class DocumentStatusApi(DocumentResource):
document = self.get_document(dataset_id, document_id) document = self.get_document(dataset_id, document_id)
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
indexing_cache_key = 'document_{}_indexing'.format(document.id) indexing_cache_key = 'document_{}_indexing'.format(document.id)
......
...@@ -123,7 +123,7 @@ class DatasetDocumentSegmentApi(Resource): ...@@ -123,7 +123,7 @@ class DatasetDocumentSegmentApi(Resource):
# check user's model setting # check user's model setting
DatasetService.check_dataset_model_setting(dataset) DatasetService.check_dataset_model_setting(dataset)
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
try: try:
...@@ -219,7 +219,7 @@ class DatasetDocumentSegmentAddApi(Resource): ...@@ -219,7 +219,7 @@ class DatasetDocumentSegmentAddApi(Resource):
if not document: if not document:
raise NotFound('Document not found.') raise NotFound('Document not found.')
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
# check embedding model setting # check embedding model setting
if dataset.indexing_technique == 'high_quality': if dataset.indexing_technique == 'high_quality':
...@@ -298,7 +298,7 @@ class DatasetDocumentSegmentUpdateApi(Resource): ...@@ -298,7 +298,7 @@ class DatasetDocumentSegmentUpdateApi(Resource):
if not segment: if not segment:
raise NotFound('Segment not found.') raise NotFound('Segment not found.')
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
try: try:
DatasetService.check_dataset_permission(dataset, current_user) DatasetService.check_dataset_permission(dataset, current_user)
...@@ -342,7 +342,7 @@ class DatasetDocumentSegmentUpdateApi(Resource): ...@@ -342,7 +342,7 @@ class DatasetDocumentSegmentUpdateApi(Resource):
if not segment: if not segment:
raise NotFound('Segment not found.') raise NotFound('Segment not found.')
# The role of the current user in the ta table must be admin or owner # The role of the current user in the ta table must be admin or owner
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
try: try:
DatasetService.check_dataset_permission(dataset, current_user) DatasetService.check_dataset_permission(dataset, current_user)
......
...@@ -98,7 +98,7 @@ class ModelProviderApi(Resource): ...@@ -98,7 +98,7 @@ class ModelProviderApi(Resource):
@login_required @login_required
@account_initialization_required @account_initialization_required
def post(self, provider: str): def post(self, provider: str):
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
parser = reqparse.RequestParser() parser = reqparse.RequestParser()
...@@ -122,7 +122,7 @@ class ModelProviderApi(Resource): ...@@ -122,7 +122,7 @@ class ModelProviderApi(Resource):
@login_required @login_required
@account_initialization_required @account_initialization_required
def delete(self, provider: str): def delete(self, provider: str):
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
model_provider_service = ModelProviderService() model_provider_service = ModelProviderService()
...@@ -159,7 +159,7 @@ class PreferredProviderTypeUpdateApi(Resource): ...@@ -159,7 +159,7 @@ class PreferredProviderTypeUpdateApi(Resource):
@login_required @login_required
@account_initialization_required @account_initialization_required
def post(self, provider: str): def post(self, provider: str):
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
tenant_id = current_user.current_tenant_id tenant_id = current_user.current_tenant_id
......
...@@ -43,7 +43,7 @@ class ToolBuiltinProviderDeleteApi(Resource): ...@@ -43,7 +43,7 @@ class ToolBuiltinProviderDeleteApi(Resource):
@login_required @login_required
@account_initialization_required @account_initialization_required
def post(self, provider): def post(self, provider):
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
user_id = current_user.id user_id = current_user.id
...@@ -60,7 +60,7 @@ class ToolBuiltinProviderUpdateApi(Resource): ...@@ -60,7 +60,7 @@ class ToolBuiltinProviderUpdateApi(Resource):
@login_required @login_required
@account_initialization_required @account_initialization_required
def post(self, provider): def post(self, provider):
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
user_id = current_user.id user_id = current_user.id
...@@ -90,7 +90,7 @@ class ToolApiProviderAddApi(Resource): ...@@ -90,7 +90,7 @@ class ToolApiProviderAddApi(Resource):
@login_required @login_required
@account_initialization_required @account_initialization_required
def post(self): def post(self):
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
user_id = current_user.id user_id = current_user.id
...@@ -159,7 +159,7 @@ class ToolApiProviderUpdateApi(Resource): ...@@ -159,7 +159,7 @@ class ToolApiProviderUpdateApi(Resource):
@login_required @login_required
@account_initialization_required @account_initialization_required
def post(self): def post(self):
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
user_id = current_user.id user_id = current_user.id
...@@ -193,7 +193,7 @@ class ToolApiProviderDeleteApi(Resource): ...@@ -193,7 +193,7 @@ class ToolApiProviderDeleteApi(Resource):
@login_required @login_required
@account_initialization_required @account_initialization_required
def post(self): def post(self):
if current_user.current_tenant.current_role not in ['admin', 'owner']: if not current_user.is_admin_or_owner:
raise Forbidden() raise Forbidden()
user_id = current_user.id user_id = current_user.id
......
...@@ -76,7 +76,7 @@ def validate_dataset_token(view=None): ...@@ -76,7 +76,7 @@ def validate_dataset_token(view=None):
.filter(Tenant.id == api_token.tenant_id) \ .filter(Tenant.id == api_token.tenant_id) \
.filter(TenantAccountJoin.tenant_id == Tenant.id) \ .filter(TenantAccountJoin.tenant_id == Tenant.id) \
.filter(TenantAccountJoin.role.in_(['owner'])) \ .filter(TenantAccountJoin.role.in_(['owner'])) \
.one_or_none() .one_or_none() # TODO: only owner information is required, so only one is returned.
if tenant_account_join: if tenant_account_join:
tenant, ta = tenant_account_join tenant, ta = tenant_account_join
account = Account.query.filter_by(id=ta.account_id).first() account = Account.query.filter_by(id=ta.account_id).first()
...@@ -86,9 +86,9 @@ def validate_dataset_token(view=None): ...@@ -86,9 +86,9 @@ def validate_dataset_token(view=None):
current_app.login_manager._update_request_context_with_user(account) current_app.login_manager._update_request_context_with_user(account)
user_logged_in.send(current_app._get_current_object(), user=_get_user()) user_logged_in.send(current_app._get_current_object(), user=_get_user())
else: else:
raise Unauthorized("Tenant owner account is not exist.") raise Unauthorized("Tenant owner account does not exist.")
else: else:
raise Unauthorized("Tenant is not exist.") raise Unauthorized("Tenant does not exist.")
return view(api_token.tenant_id, *args, **kwargs) return view(api_token.tenant_id, *args, **kwargs)
return decorated return decorated
......
...@@ -101,7 +101,10 @@ class Account(UserMixin, db.Model): ...@@ -101,7 +101,10 @@ class Account(UserMixin, db.Model):
return db.session.query(ai).filter( return db.session.query(ai).filter(
ai.account_id == self.id ai.account_id == self.id
).all() ).all()
# check current_user.current_tenant.current_role in ['admin', 'owner']
@property
def is_admin_or_owner(self):
return self._current_tenant.current_role in ['admin', 'owner']
class Tenant(db.Model): class Tenant(db.Model):
__tablename__ = 'tenants' __tablename__ = 'tenants'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment