Skip to content

Commit

Permalink
Add homepage setting
Browse files Browse the repository at this point in the history
  • Loading branch information
kozzzx committed Oct 20, 2023
1 parent edde15a commit 919c4c3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/apis/site_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ def put(self):
site_setting.whitelist_emails = data["whitelist_emails"]
site_setting.only_allow_admin_create_team = data["only_allow_admin_create_team"]
site_setting.auto_join_team_ids = data["auto_join_team_ids"]
site_setting.homepage_html = data["homepage_html"]
site_setting.homepage_css = data["homepage_css"]
site_setting.save()
site_setting.reload()
return site_setting.to_api()


class HomepageAPI(MoeAPIView):
def get(self):
return {
"html": SiteSetting.get().homepage_html,
"css": SiteSetting.get().homepage_css,
}
7 changes: 6 additions & 1 deletion app/apis/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
MeRelatedApplicationListAPI,
)
from app.apis.avatar import AvatarAPI
from app.apis.site_setting import SiteSettingAPI
from app.apis.site_setting import HomepageAPI, SiteSettingAPI
from app.apis.user import (
AdminUserAPI,
AdminUserAdminStatusAPI,
Expand Down Expand Up @@ -92,6 +92,11 @@
index.add_url_rule(
"/error", methods=["GET", "OPTIONS"], view_func=ErrorAPI.as_view("error")
)
# site公开配置模块
site = Blueprint("site", __name__, url_prefix=v1_prefix + "/site")
site.add_url_rule(
"/homepage", methods=["GET", "OPTIONS"], view_func=HomepageAPI.as_view("homepage")
)
# type模块
type = Blueprint("type", __name__, url_prefix=v1_prefix + "/types")
type.add_url_rule(
Expand Down
4 changes: 4 additions & 0 deletions app/models/site_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class SiteSetting(Document):
whitelist_emails = ListField(StringField(), db_field="we", default=list)
only_allow_admin_create_team = BooleanField(db_field="oacg", default=True)
auto_join_team_ids = ListField(ObjectIdField(), db_field="ajt", default=list)
homepage_html = StringField(db_field="h", default="")
homepage_css = StringField(db_field="hc", default="")

meta = {
"indexes": [
Expand All @@ -44,4 +46,6 @@ def to_api(self):
"whitelist_emails": self.whitelist_emails,
"only_allow_admin_create_team": self.only_allow_admin_create_team,
"auto_join_team_ids": [str(id) for id in self.auto_join_team_ids],
"homepage_html": self.homepage_html,
"homepage_css": self.homepage_css,
}
2 changes: 2 additions & 0 deletions app/validators/site_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ class SiteSettingSchema(Schema):
required=True,
error_messages={**required_message},
)
homepage_html = fields.Str()
homepage_css = fields.Str()

0 comments on commit 919c4c3

Please sign in to comment.