mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-26 20:25:11 -05:00
feat(frontend): ✨ add group permissions (#721)
* style(frontend): 💄 add darktheme custom * add dummy users in dev mode * feat(frontend): ✨ add group permissions editor UI * feat(backend): ✨ add group permissions setters * test(backend): ✅ tests for basic permission get/set (WIP) Needs more testing * remove old test * chore(backend): copy template.env on setup * feat(frontend): ✨ enable send invitation via email * feat(backend): ✨ enable send invitation via email * feat: ✨ add app config checker for site-settings * refactor(frontend): ♻️ consolidate bool checks Co-authored-by: Hayden <hay-kot@pm.me>
This commit is contained in:
61
mealie/db/data_initialization/init_users.py
Normal file
61
mealie/db/data_initialization/init_users.py
Normal file
@@ -0,0 +1,61 @@
|
||||
from mealie.core import root_logger
|
||||
from mealie.core.config import settings
|
||||
from mealie.core.security import hash_password
|
||||
from mealie.db.data_access_layer.access_model_factory import Database
|
||||
|
||||
logger = root_logger.get_logger("init_users")
|
||||
|
||||
|
||||
def dev_users() -> list[dict]:
|
||||
return [
|
||||
{
|
||||
"full_name": "Jason",
|
||||
"username": "jason",
|
||||
"email": "jason@email.com",
|
||||
"password": hash_password(settings.DEFAULT_PASSWORD),
|
||||
"group": settings.DEFAULT_GROUP,
|
||||
"admin": False,
|
||||
},
|
||||
{
|
||||
"full_name": "Bob",
|
||||
"username": "bob",
|
||||
"email": "bob@email.com",
|
||||
"password": hash_password(settings.DEFAULT_PASSWORD),
|
||||
"group": settings.DEFAULT_GROUP,
|
||||
"admin": False,
|
||||
},
|
||||
{
|
||||
"full_name": "Sarah",
|
||||
"username": "sarah",
|
||||
"email": "sarah@email.com",
|
||||
"password": hash_password(settings.DEFAULT_PASSWORD),
|
||||
"group": settings.DEFAULT_GROUP,
|
||||
"admin": False,
|
||||
},
|
||||
{
|
||||
"full_name": "Sammy",
|
||||
"username": "sammy",
|
||||
"email": "sammy@email.com",
|
||||
"password": hash_password(settings.DEFAULT_PASSWORD),
|
||||
"group": settings.DEFAULT_GROUP,
|
||||
"admin": False,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def default_user_init(db: Database):
|
||||
default_user = {
|
||||
"full_name": "Change Me",
|
||||
"username": "admin",
|
||||
"email": settings.DEFAULT_EMAIL,
|
||||
"password": hash_password(settings.DEFAULT_PASSWORD),
|
||||
"group": settings.DEFAULT_GROUP,
|
||||
"admin": True,
|
||||
}
|
||||
|
||||
logger.info("Generating Default User")
|
||||
db.users.create(default_user)
|
||||
|
||||
if not settings.PRODUCTION:
|
||||
for user in dev_users():
|
||||
db.users.create(user)
|
||||
@@ -1,8 +1,8 @@
|
||||
from mealie.core import root_logger
|
||||
from mealie.core.config import settings
|
||||
from mealie.core.security import hash_password
|
||||
from mealie.db.data_access_layer.access_model_factory import Database
|
||||
from mealie.db.data_initialization.init_units_foods import default_recipe_unit_init
|
||||
from mealie.db.data_initialization.init_users import default_user_init
|
||||
from mealie.db.database import get_database
|
||||
from mealie.db.db_setup import create_session, engine
|
||||
from mealie.db.models._model_base import SqlAlchemyBase
|
||||
@@ -37,20 +37,6 @@ def default_group_init(db: Database):
|
||||
create_new_group(db, GroupBase(name=settings.DEFAULT_GROUP))
|
||||
|
||||
|
||||
def default_user_init(db: Database):
|
||||
default_user = {
|
||||
"full_name": "Change Me",
|
||||
"username": "admin",
|
||||
"email": settings.DEFAULT_EMAIL,
|
||||
"password": hash_password(settings.DEFAULT_PASSWORD),
|
||||
"group": settings.DEFAULT_GROUP,
|
||||
"admin": True,
|
||||
}
|
||||
|
||||
logger.info("Generating Default User")
|
||||
db.users.create(default_user)
|
||||
|
||||
|
||||
def main():
|
||||
create_all_models()
|
||||
|
||||
|
||||
@@ -34,8 +34,12 @@ class User(SqlAlchemyBase, BaseMixins):
|
||||
group_id = Column(Integer, ForeignKey("groups.id"))
|
||||
group = orm.relationship("Group", back_populates="users")
|
||||
|
||||
# Recipes
|
||||
# Group Permissions
|
||||
can_manage = Column(Boolean, default=False)
|
||||
can_invite = Column(Boolean, default=False)
|
||||
can_organize = Column(Boolean, default=False)
|
||||
|
||||
# Recipes
|
||||
tokens: list[LongLiveToken] = orm.relationship(
|
||||
LongLiveToken, back_populates="user", cascade="all, delete, delete-orphan", single_parent=True
|
||||
)
|
||||
@@ -59,6 +63,9 @@ class User(SqlAlchemyBase, BaseMixins):
|
||||
group: str = settings.DEFAULT_GROUP,
|
||||
admin=False,
|
||||
advanced=False,
|
||||
can_manage=False,
|
||||
can_invite=False,
|
||||
can_organize=False,
|
||||
**_
|
||||
) -> None:
|
||||
|
||||
@@ -71,6 +78,15 @@ class User(SqlAlchemyBase, BaseMixins):
|
||||
self.password = password
|
||||
self.advanced = advanced
|
||||
|
||||
if self.admin:
|
||||
self.can_manage = True
|
||||
self.can_invite = True
|
||||
self.can_organize = True
|
||||
else:
|
||||
self.can_manage = can_manage
|
||||
self.can_invite = can_invite
|
||||
self.can_organize = can_organize
|
||||
|
||||
self.favorite_recipes = []
|
||||
|
||||
if self.username is None:
|
||||
@@ -87,6 +103,9 @@ class User(SqlAlchemyBase, BaseMixins):
|
||||
favorite_recipes=None,
|
||||
password=None,
|
||||
advanced=False,
|
||||
can_manage=False,
|
||||
can_invite=False,
|
||||
can_organize=False,
|
||||
**_
|
||||
):
|
||||
favorite_recipes = favorite_recipes or []
|
||||
@@ -103,6 +122,15 @@ class User(SqlAlchemyBase, BaseMixins):
|
||||
if password:
|
||||
self.password = password
|
||||
|
||||
if self.admin:
|
||||
self.can_manage = True
|
||||
self.can_invite = True
|
||||
self.can_organize = True
|
||||
else:
|
||||
self.can_manage = can_manage
|
||||
self.can_invite = can_invite
|
||||
self.can_organize = can_organize
|
||||
|
||||
def update_password(self, password):
|
||||
self.password = password
|
||||
|
||||
|
||||
Reference in New Issue
Block a user