-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1797 from Bidaya0/feat/add-project-token
Feat/add project token
- Loading branch information
Showing
8 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Generated by Django 3.2.20 on 2023-09-11 14:16 | ||
|
||
import shortuuid.django_fields | ||
from django.db import migrations | ||
from shortuuid import ShortUUID | ||
|
||
|
||
def update_exist_project_token(apps, schema_editor): | ||
IastProject = apps.get_model("dongtai_common", "IastProject") | ||
objs_list = [] | ||
for project in IastProject.objects.all(): | ||
project.token = ShortUUID(alphabet="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789").random( | ||
length=22 | ||
) | ||
objs_list.append(project) | ||
IastProject.objects.bulk_update(objs_list, ["token"]) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("dongtai_common", "0021_iastwebhooklog"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="iastproject", | ||
name="token", | ||
field=shortuuid.django_fields.ShortUUIDField( | ||
alphabet="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", | ||
length=22, | ||
max_length=22, | ||
prefix="", | ||
), | ||
), | ||
migrations.RunPython(update_exist_project_token), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from dongtai_common.endpoint import R, UserEndPoint | ||
from dongtai_web.utils import extend_schema_with_envcheck | ||
|
||
|
||
class ProjectToken(UserEndPoint): | ||
@extend_schema_with_envcheck( | ||
tags=[_("Project")], | ||
summary=_("Projects Token"), | ||
description=_( | ||
"Get project information by project id, including the current version information of the project." | ||
), | ||
) | ||
def get(self, request, pk): | ||
project = request.user.get_projects().filter(pk=pk).first() | ||
if project: | ||
return R.success( | ||
data={ | ||
"id": project.id, | ||
"token": project.token, | ||
} | ||
) | ||
return R.failure(status=203, msg=_("no permission")) |