-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: Application access restrictions are not separately counted for each application #1937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Generated by Django 4.2.15 on 2024-12-27 18:42 | ||
|
|
||
| from django.db import migrations, models | ||
| import uuid | ||
|
|
||
| run_sql = """ | ||
| UPDATE application_public_access_client | ||
| SET client_id="id" | ||
| """ | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ('application', '0020_application_record_update_time'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='applicationpublicaccessclient', | ||
| name='client_id', | ||
| field=models.UUIDField(default=uuid.uuid1, verbose_name='公共访问链接客户端id'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='applicationpublicaccessclient', | ||
| name='id', | ||
| field=models.UUIDField(default=uuid.uuid1, editable=False, primary_key=True, serialize=False, | ||
| verbose_name='主键id'), | ||
| ), | ||
| migrations.AddIndex( | ||
| model_name='applicationpublicaccessclient', | ||
| index=models.Index(fields=['client_id'], name='application_client__4de9af_idx'), | ||
| ), | ||
| migrations.RunSQL(run_sql) | ||
| ] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code has several potential issues and optimization suggestions:
Here's an improved version of the code addressing these considerations: @@ -0,0 +1,32 @@
# Generated by Django 4.2.15 on 2024-12-27 18:42
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
('application', '0020_application_record_update_time'),
]
operations = [
migrations.AddField(
model_name='applicationpublicaccessclient',
name='client_id',
field=models.UUIDField(default=uuid.uuid1, verbose_name='公共访问链接客户端ID'),
),
# Move any additional changes here
]If you need to perform specific actions like updating records during migrations, consider creating a custom management command outside of Django ORM for better clarity: |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,8 @@ | |
| @date:2023/11/14 13:51 | ||
| @desc: | ||
| """ | ||
| from datetime import datetime | ||
| import uuid | ||
| from datetime import datetime | ||
| from typing import List, Dict | ||
| from uuid import UUID | ||
|
|
||
|
|
@@ -107,7 +107,8 @@ def to_base_pipeline_manage_params(self): | |
| 'search_mode': self.application.dataset_setting.get( | ||
| 'search_mode') if 'search_mode' in self.application.dataset_setting else 'embedding', | ||
| 'no_references_setting': self.get_no_references_setting(self.application.dataset_setting, model_setting), | ||
| 'user_id': self.application.user_id | ||
| 'user_id': self.application.user_id, | ||
| 'application_id': self.application.id | ||
| } | ||
|
|
||
| def to_pipeline_manage_params(self, problem_text: str, post_response_handler: PostResponseHandler, | ||
|
|
@@ -258,9 +259,11 @@ def is_valid_chat_id(self, chat_info: ChatInfo): | |
|
|
||
| def is_valid_intraday_access_num(self): | ||
| if self.data.get('client_type') == AuthenticationType.APPLICATION_ACCESS_TOKEN.value: | ||
| access_client = QuerySet(ApplicationPublicAccessClient).filter(id=self.data.get('client_id')).first() | ||
| access_client = QuerySet(ApplicationPublicAccessClient).filter(client_id=self.data.get('client_id'), | ||
| application_id=self.data.get( | ||
| 'application_id')).first() | ||
| if access_client is None: | ||
| access_client = ApplicationPublicAccessClient(id=self.data.get('client_id'), | ||
| access_client = ApplicationPublicAccessClient(client_id=self.data.get('client_id'), | ||
| application_id=self.data.get('application_id'), | ||
| access_num=0, | ||
| intraday_access_num=0) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code has a few improvements and clarifications that can be made:
Revised Code"""
@author:zhangsan
@data:2023/11/14 13:51
@desc:
"""
import uuid
from datetime import datetime
from typing import *
from uuid import UUID
class PostResponseHandler:
# Method definition here...
class AuthenticationType(Enum):
APPLICATION_ACCESS_TOKEN = "APPLICATION_ACCESS_TOKEN"
class ApplicationPublicAccessClient(BaseModel):
client_id: int
application_id: int
access_num: int
intraday_access_num: int
class BaseModel(metaclass=abstractmeta):
pass
def get_no_references_setting(dataset_settings: dict, model_setting: Optional[Dict] = None) -> Union[List[str], str]:
no_reference_setting = dataset_settings.get("no_reference_setting")
return no_reference_setting
def to_base_pipeline_manage_params(self, user_id, problem_text=None, model_setting=None):
"""
Converts various parameters to pipeline manage params.
:param user_id: User ID associated with the parameters.
:param problem_text: Text related to the problem for which data is being collected.
:param model_setting: Additional settings specific to the model used for processing (optional).
:return: A dictionary representing the base parameters for pipeline management.
"""
common_params = {
'search_mode': self.application.dataset_setting.get(
'search_mode', default='embedding'),
'no_references_setting': get_no_references_setting(self.application.dataset_setting, model_setting),
'user_id': user_id
}
return common_params
def to_pipeline_manage_params(self, problem_text: str, post_response_handler: PostResponseHandler,
user_id): ...
def is_valid_chat_id(self, chat_info: ChatInfo):
# Method implementation here...
def is_valid_intraday_access_num(self):
if self.data.get('client_type') == AuthenticationType.APPLICATION_ACCESS_TOKEN.value:
access_client = (
QuerySet(ApplicationPublicAccessClient)
.filter(client_id=self.data.get('client_id'), application_id=self.data.get('application_id'))
.first()
)
if not access_client:
access_client = (
ApplicationPublicAccessClient(
id=self.data.get('client_id'),
application_id=self.data.get('application_id'),
access_num=0,
intraday_access_num=0
)
)
# Define any other methods or classes here...These changes improve the clarity and maintainability of the code while adhering to best practices in Python programming, such as naming conventions and avoiding redundant imports. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks mostly correct for managing access numbers based on user interactions, but there are a few improvements and clarifications that can be made:
Improvements and Clarifications
Parameter Naming: The
application_idparameter should be renamed to something more meaningful likeaccess_codeorauth_code, as it indicates an access code rather than just a client ID.Code Logic:
client_typeis not equal toAuthenticationType.APPLICATION_ACCESS_TOKEN.client_id,client_type) are provided before attempting database operations.Logging:
add_access_numis called, which might help in debugging issues.Optimizations
Since this function does not directly impact performance, no optimizations are necessary aside from these minor improvements.
Potential Issues
Missing Error Handling: Although covered with try-except blocks, additional error handling (e.g., checking if
application_public_access_clientexists) can enhance robustness.Database Constraints: Ensure that the constraints enforce unique combinations of
client_idandapplication_idif needed.Here's the revised version with some suggested changes:
By implementing these changes, you improve maintainability and future-proofing of the codebase.