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/mub roles+permissions #6

Closed
wants to merge 5 commits into from
Closed

Feat/mub roles+permissions #6

wants to merge 5 commits into from

Conversation

waldemarX
Copy link

No description provided.

Copy link

@max31ru12 max31ru12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Красивое решение очень интересной и объемной задачи!

Copy link

@max31ru12 max31ru12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Все отлично!

Copy link
Member

@niqzart niqzart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пока так, тесты гляну после фиксов, потому что есть значительные

app/communities/models/roles_db.py Outdated Show resolved Hide resolved
app/communities/models/roles_db.py Show resolved Hide resolved
app/communities/models/permissions_db.py Outdated Show resolved Hide resolved
app/communities/models/roles_db.py Outdated Show resolved Hide resolved
app/communities/routes/participants_roles_mub.py Outdated Show resolved Hide resolved
app/communities/routes/participants_roles_mub.py Outdated Show resolved Hide resolved
app/communities/routes/participants_roles_mub.py Outdated Show resolved Hide resolved
app/communities/routes/permissions_mub.py Outdated Show resolved Hide resolved
app/communities/models/participants_db.py Outdated Show resolved Hide resolved
app/communities/routes/participants_roles_mub.py Outdated Show resolved Hide resolved
@waldemarX waldemarX force-pushed the feat/mub-roles branch 2 times, most recently from 5e07b27 to 5d36bd5 Compare May 22, 2024 17:34
Copy link
Member

@niqzart niqzart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Интересное, поулчилось решение. Тут много копирования, так что напомню, твой код это твой код. Оправдание "так было в xi.backend" не работает, в xi.backend был flask, pip и по 6 декораторов на функцию

app/communities/models/participants_db.py Outdated Show resolved Hide resolved
app/communities/main.py Outdated Show resolved Hide resolved
app/communities/models/roles_db.py Outdated Show resolved Hide resolved
app/communities/models/roles_db.py Outdated Show resolved Hide resolved
app/communities/models/roles_db.py Outdated Show resolved Hide resolved
app/communities/models/roles_db.py Outdated Show resolved Hide resolved
app/communities/routes/roles_mub.py Outdated Show resolved Hide resolved
Comment on lines +33 to +35
permissions: Mapped[list["RolePermission"]] = relationship(
passive_deletes=True, cascade="all, delete-orphan", lazy="selectin"
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: ORM-каскады не совместимы с constraints на ForeignKey (ondelete="cascade")

Comment on lines +32 to +33
community: Mapped[Community] = relationship(passive_deletes=True)
permissions: Mapped[list["RolePermission"]] = relationship(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: Раз разделяем отношения пустыми строчками, перед permissions тоже

Comment on lines +37 to +38
@property
def permission_list(self) -> list[Permission]: # noqa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue:

  1. Никогда нельзя использовать noqa без указания ошибки
  2. Линтер абсолютно прав, название фигня, списки списками не зовут

Comment on lines +20 to +22
summary="Provide a role to a participant",
)
async def provide_role_to_participant(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: некорректный и неконсистентный неминг (а было лучше с assign)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Раз уж в participants точно такая же предзагрузка ролей, что в ролях для разрешений, можно и API совместить с participants_mub. Assign и deassign можно оставить отдельными методами, но получение добавить в модель для retrieve

Comment on lines +54 to +56
exclude={
"permissions",
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: без запятой (или с запятой после }) компактнее

Comment on lines +59 to +66
if role_data.permissions:
role.permissions.clear()
role.permissions.extend(
[
RolePermission(role_id=role.id, permission=permission)
for permission in role_data.permissions
]
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (repeat): сначала убрать всё, затем добавить всё. Нет

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мы, кстати, обычно отношениями ORM не пользуемся

Copy link
Member

@niqzart niqzart May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем эта логика в контроллере тоже особо не понимаю (может и меет место быть, но странно)

Comment on lines +58 to +59
)
if role_data.permissions:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (ну камон): if на непонятное условие. permissions это не bool, обязательно уточнять, что ты проверяешь. А тут это даже ведёт к некорректному поведению: невозможно отчистить список разрешений

Comment on lines +40 to +41
permissions: list[Permission] | None

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Не используется PatchDefault, а должен. None тут не при делах

Comment on lines +8 to +9
router = APIRouterExt(tags=["roles meta mub"])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: теперь meta не имеет смысла

@niqzart niqzart force-pushed the staging branch 3 times, most recently from 1c99138 to 96c5d21 Compare July 27, 2024 18:19
@niqzart
Copy link
Member

niqzart commented Sep 14, 2024

Closed in favour of #25

@niqzart niqzart closed this Sep 14, 2024
@niqzart niqzart deleted the feat/mub-roles branch September 14, 2024 19:31
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.

3 participants