-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: apis for applications management page #20
Conversation
module default { | ||
scalar type TagType extending enum<Permission>; | ||
|
||
type Tag extending TimeStamped { |
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.
Do tags need to be associated with an application?
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.
Not necessary so far. Now we make all tags equally global.
import edgedb | ||
from fastapi import Depends | ||
|
||
from freeauth.applications.dataclasses import ( |
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.
(minor) use relative import for local packages
from .dataclasses import ...
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.
fixed in a946392
and according to Xenia's advice, set the default format for import module
to relative
in Pylance.
) | ||
except edgedb.errors.ConstraintViolationError: | ||
raise HTTPException( | ||
status_code=HTTPStatus.BAD_REQUEST, | ||
detail={"code": f"{body.code} 已被使用"}, | ||
) | ||
if not permission: |
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.
needs to catch the edgedb.errors.MissingRequiredError
exception here.
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.
fixed in a946392
Sorry for my stupid copy-paste
@@ -5,7 +5,7 @@ | |||
from pydantic import Field, validator | |||
from pydantic.dataclasses import dataclass | |||
|
|||
from ..dataclasses import BaseModelConfig | |||
from ..dataclasses import BaseModelConfig, QueryBody |
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.
need to add this import here: from ..dataclasses import FilterItem # noqa
, otherwise it will throw an error when loading Redoc and Swagger.
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.
fixed in a946392
But I feel this kind of thing is a bit of magic
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.
yes, I couldn't find a better solution, we'll have to go with this workaround for now.
@@ -141,7 +148,7 @@ async def put_permission( | |||
) | |||
if not permission: | |||
raise HTTPException( | |||
status_code=HTTPStatus.NOT_FOUND, detail="角色不存在" | |||
status_code=HTTPStatus.NOT_FOUND, detail="权限不存在" | |||
) | |||
except edgedb.errors.ConstraintViolationError: |
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.
If the tag name is duplicated, it will also raise edgedb.errors.ConstraintViolationError
error. You can refer to this way to handle different unique fields.
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.
Alternatively, you can pass one parameter tags and check for conflicts during the INSERT
operation in EdgeQL. For example:
insert Permission {
...
tags := (
for item in array_unpack(<array<str>>$tags) union (
insert Tag {
name := item,
tag_type := TagType.Permission
} unless conflict on .name
else (
select Tag filter .name = item and .tag_type = TagType.Permission
)
)
)
}
No description provided.