Skip to content
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

Merged
merged 2 commits into from
May 22, 2023

Conversation

daichen-daisy
Copy link
Member

No description provided.

@daichen-daisy daichen-daisy requested a review from XeniaLu May 20, 2023 22:05
module default {
scalar type TagType extending enum<Permission>;

type Tag extending TimeStamped {
Copy link
Member

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?

Copy link
Member Author

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 (
Copy link
Member

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 ...

Copy link
Member Author

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:
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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.

@daichen-daisy daichen-daisy requested a review from XeniaLu May 22, 2023 00:24
@@ -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:
Copy link
Member

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.

Copy link
Member

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
            )
        )
    )
}

@XeniaLu XeniaLu merged commit 21e49cf into decentfox:main May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants