Skip to content

Commit

Permalink
wip Fix #1281 Can add/edit plan managers as a shop owner
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsimpson committed Feb 18, 2024
1 parent d1c6b77 commit 84c6856
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
25 changes: 23 additions & 2 deletions subscribie/blueprints/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -646,15 +656,25 @@ 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"])
@login_required
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
Expand Down Expand Up @@ -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"])
Expand Down
22 changes: 22 additions & 0 deletions subscribie/blueprints/admin/templates/admin/add_plan.html
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,28 @@ <h2 class="text-center text-dark mb-3">Create a new plan</h2>
Time (e.g. midnight)
</small>
</div>

<div class="form-group ">
<div class="form-check">
<input type="checkbox" value="yes" class="form-check-input toggle" name="managers_set-0" id="managers_set-0">
<label class="form-check-label font-weight-bolder" for="managers_set-0">Managers</label>
</div>
<small class="form-text text-muted">
If you have lots of plans, and have multiple people in your business, you can
assign your shop admin(s) to those plans.
</small>
</div>
<div class="form-group extra_fields" id="managers" >
{% for user in users %}
<div class="form-check">
<input class="form-check-input" type="checkbox" name="user-{{ user.id }}" value="{{ user.id }}" id="user-{{ user.id }}">
<label class="form-check-label" for="user-{{ user.id }}">
{{ user.email }}
</label>
</div>
{% endfor %}
</div>

</fieldset>

<button type="submit" class="disable-on-click btn btn-primary btn-block my-3 mx-auto">Save</button>
Expand Down
35 changes: 34 additions & 1 deletion subscribie/blueprints/admin/templates/admin/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ <h2 class="text-center text-dark mb-3">Edit Plans</h2>
<div class="form-check">
<input type="hidden" class="subscription-check" data-id="{{ loop.index0 }}" name="subscription-{{ loop.index0 }}" value="no">
<input type="checkbox" value="yes" class="form-check-input toggle" name="subscription-{{ loop.index0 }}" id="subscription-{{ loop.index0 }}" {% if plan.requirements.subscription %} checked {% endif %}>
<label class="form-check-label font-weight-bolder" for="subscription-{{ loop.index0 }}">Recurring Charge?</label>
<label class="form-check-label font-weight-bolder" for="subscription-{{ loop.index0 }}">Recurring charge?</label>
</div>
</div>

Expand Down Expand Up @@ -233,6 +233,39 @@ <h2 class="text-center text-dark mb-3">Edit Plans</h2>
Then, you can send a link to your customer(s) to sign-up to the private plan.
</small>
</div>


<div class="form-group">
<div class="form-check">
<input type="checkbox" value="yes" class="form-check-input toggle" name="manager-{{ loop.index0 }}" id="manager-{{ loop.index0 }}"
{% if plan.managers | length > 0 %} checked {% endif %} />

<label class="form-check-label font-weight-bolder" for="manager-{{ loop.index0 }}">Manager(s)</label>
</div>
<small class="form-text text-muted">
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.
</small>
</div>

<div class="extra_fields">
<div class="form-group">
{% set outer_loop = loop %}
{% for user in users %}
<div class="form-check">
<input class="form-check-input" type="checkbox" name="managers-index-{{ outer_loop.index0 }}" value="{{ user.id }}" id="manager-{{ user.id }}"
{% if user in plan.managers %}
checked
{% endif %} />
<label class="form-check-label" for="manager-{{ user.id }}">
{{ user.email }}
</label>
</div>
{% endfor %}
</div>
</div>


<a href="{{url_for("views.view_plan", uuid=plan.uuid, plan_title=plan.title)}}" target="_blank">Share URL</a>
</fieldset>
<!-- end plan description & settings -->
Expand Down
3 changes: 3 additions & 0 deletions subscribie/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class PlansForm(StripWhitespaceForm):
description = FieldList(
StringField("Description", [validators.optional()], default=False)
)
managers = FieldList(
BooleanField("Managers", [validators.optional()])
)


class ChoiceGroupForm(FlaskForm):
Expand Down

0 comments on commit 84c6856

Please sign in to comment.