From 84c6856cf72489ed58bed9d68554db0b8ad7431e Mon Sep 17 00:00:00 2001 From: chrisjsimpson Date: Sun, 18 Feb 2024 20:56:44 +0000 Subject: [PATCH] wip Fix #1281 Can add/edit plan managers as a shop owner --- ...111e416_merge_9083452d3a80_bb76d2149316.py | 24 +++++++++++++ subscribie/blueprints/admin/__init__.py | 25 +++++++++++-- .../admin/templates/admin/add_plan.html | 22 ++++++++++++ .../admin/templates/admin/edit.html | 35 ++++++++++++++++++- subscribie/forms.py | 3 ++ 5 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 migrations/versions/535f7111e416_merge_9083452d3a80_bb76d2149316.py diff --git a/migrations/versions/535f7111e416_merge_9083452d3a80_bb76d2149316.py b/migrations/versions/535f7111e416_merge_9083452d3a80_bb76d2149316.py new file mode 100644 index 000000000..af2a3786b --- /dev/null +++ b/migrations/versions/535f7111e416_merge_9083452d3a80_bb76d2149316.py @@ -0,0 +1,24 @@ +"""Merge 9083452d3a80 bb76d2149316 + +Revision ID: 535f7111e416 +Revises: 9083452d3a80, bb76d2149316 +Create Date: 2024-02-17 19:03:56.495742 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '535f7111e416' +down_revision = ('9083452d3a80', 'bb76d2149316') +branch_labels = None +depends_on = None + + +def upgrade(): + pass + + +def downgrade(): + pass diff --git a/subscribie/blueprints/admin/__init__.py b/subscribie/blueprints/admin/__init__.py index 270d9f95e..367388ae8 100644 --- a/subscribie/blueprints/admin/__init__.py +++ b/subscribie/blueprints/admin/__init__.py @@ -546,6 +546,16 @@ def edit(): draftPlan.uuid = str(uuid.uuid4()) draftPlan.parent_plan_revision_uuid = plan.uuid draftPlan.requirements = plan_requirements + + # Preserve / update managers assigned to plan + managers = [] + managersUserIds = request.form.getlist(f'managers-index-{index}') + for userId in managersUserIds: + user = User.query.get(int(userId)) + managers.append(user) + draftPlan.managers.clear() + draftPlan.managers.extend(managers) + # Preserve primary icon if exists draftPlan.primary_icon = plan.primary_icon @@ -646,7 +656,8 @@ def edit(): database.session.commit() # Save flash("Plan(s) updated.") return redirect(url_for("admin.edit")) - return render_template("admin/edit.html", plans=plans, form=form) + users = User.query.all() + return render_template("admin/edit.html", plans=plans, form=form, users=users) @admin.route("/add", methods=["GET", "POST"]) @@ -654,7 +665,16 @@ def edit(): def add_plan(): form = PlansForm() if form.validate_on_submit(): + # Get managers if assigned + users = User.query.all() + managers = [] + for user in users: + if request.form.get(f"user-{user.id}"): + user = User.query.get(int(request.form.get(f"user-{user.id}"))) + managers.append(user) + draftPlan = Plan() + draftPlan.managers.extend(managers) database.session.add(draftPlan) plan_requirements = PlanRequirements() draftPlan.requirements = plan_requirements @@ -759,7 +779,8 @@ def add_plan(): database.session.commit() flash("Plan added.") return redirect(url_for("admin.dashboard")) - return render_template("admin/add_plan.html", form=form) + users = User.query.all() + return render_template("admin/add_plan.html", form=form, users=users) @admin.route("/delete", methods=["GET"]) diff --git a/subscribie/blueprints/admin/templates/admin/add_plan.html b/subscribie/blueprints/admin/templates/admin/add_plan.html index 5255cd3af..236f4c110 100644 --- a/subscribie/blueprints/admin/templates/admin/add_plan.html +++ b/subscribie/blueprints/admin/templates/admin/add_plan.html @@ -236,6 +236,28 @@

Create a new plan

Time (e.g. midnight) + +
+
+ + +
+ + If you have lots of plans, and have multiple people in your business, you can + assign your shop admin(s) to those plans. + +
+
+ {% for user in users %} +
+ + +
+ {% endfor %} +
+ diff --git a/subscribie/blueprints/admin/templates/admin/edit.html b/subscribie/blueprints/admin/templates/admin/edit.html index 7b3050fbc..9ff7fc1d1 100644 --- a/subscribie/blueprints/admin/templates/admin/edit.html +++ b/subscribie/blueprints/admin/templates/admin/edit.html @@ -107,7 +107,7 @@

Edit Plans

- +
@@ -233,6 +233,39 @@

Edit Plans

Then, you can send a link to your customer(s) to sign-up to the private plan. + + +
+
+ 0 %} checked {% endif %} /> + + +
+ + If you have lots of plans, and have multiple people in your business, you may want to + assign your shop admin(s) to those plans. + +
+ +
+
+ {% set outer_loop = loop %} + {% for user in users %} +
+ + +
+ {% endfor %} +
+
+ + Share URL diff --git a/subscribie/forms.py b/subscribie/forms.py index d96c8ad4c..a2481a74b 100644 --- a/subscribie/forms.py +++ b/subscribie/forms.py @@ -79,6 +79,9 @@ class PlansForm(StripWhitespaceForm): description = FieldList( StringField("Description", [validators.optional()], default=False) ) + managers = FieldList( + BooleanField("Managers", [validators.optional()]) + ) class ChoiceGroupForm(FlaskForm):