Skip to content

Commit

Permalink
wip Fix #1281 As a shop owner I can assign managers to plan(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsimpson committed Feb 12, 2024
1 parent b27ffc0 commit a16a621
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""add association_table_plan_to_users
Revision ID: d80effffd83d
Revises: 48074e6225c6
Create Date: 2024-02-12 12:24:44.482877
Why?
Some shop owners want/need to assign managers (users) to
plans. For example large clubs or membership organisations which
assign a 'manager' to one or more plans.
The plan_user_associations table begins to make possible the
assignment of Users to Plans. Recall that Users (see class User
in models.py) is a shop owner (admin) which may login to the
Subscribie application.
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "d80effffd83d"
down_revision = "48074e6225c6"
branch_labels = None
depends_on = None


def upgrade():
op.create_table(
"plan_user_associations",
sa.Column("plan_uuid", sa.String(), nullable=True),
sa.Column("user_id", sa.String(), nullable=True),
sa.ForeignKeyConstraint(
["plan_uuid"],
["plan.uuid"],
),
sa.ForeignKeyConstraint(
["user_id"],
["user.id"],
),
)


def downgrade():
pass
19 changes: 19 additions & 0 deletions subscribie/blueprints/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,25 @@ def delete_plan_by_uuid(uuid):
return render_template("admin/delete_plan_choose.html", plans=plans)


@admin.route("assign-managers-to-plan")
@login_required
def assign_managers_to_plan():
"""
assign users (managers) to a plan.
Some shop owners want/need to assign managers (users) to
plans. For example large clubs or membership organisations which
assign a 'manager' to one or more plans.
The plan_user_associations table begins to make possible the
assignment of Users to Plans. Recall that Users (see class User
in models.py) is a shop owner (admin) which may login to the
Subscribie application.
"""
users = User.query.all()
return render_template("admin/assign_managers_to_plan.html", users=users)


@admin.route("/list-documents", methods=["get"])
@login_required
def list_documents():
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{% extends "admin/layout.html" %}
{% block title %} {{ title }} {% endblock %}

{% block body %}

<h2 class="text-center text-dark mb-3">Assign manager(s) to plans</h2>

<div class="container">
<ul class="breadcrumb">
<li class="breadcrumb-item"><a href="/">Shop</a></li>
<li class="breadcrumb-item"><a href="{{ url_for('admin.dashboard') }}">Manage My Shop</a></li>
<li class="breadcrumb-item"><a href="{{ url_for('admin.list_choice_groups') }}">Choice Groups</a></li>
<li class="breadcrumb-item active" aria-current="page"> Add / Edit / Delete Choice Group</li>
</ul>
</div>

<main>
<div class="section">
<div class="container">
<h3>Allow managers to quickly see plans they're responsible for</h3>
<div class="col-md-7">
<p>Some larger organisations like to assign people to 'manage' Subscribers who are subscribed to specific plans.<br />
For example, if you're a sports club or large membership organisation you can assign specific staff to
become 'managers' of specific plans. This helps them see only the Subscribers they are responsible for.</p>

<p>
Once you do so, when they login to their account, the visibility of the Subscribers they see
will be highlighted, and by default any Subscribers they are <em>not</em> a manager of given less Precedence, based
on the Plans they are assigned to as a manager.</p>
<br />
<p>
Please note this is <em>not</em> a security feature- it does <em>not</em> stop managers being able to access
all plans, it simply makes it easier for a manager of specific plans to quickly see the Subscribers
who are subscribed to the plans they manage.
</p>

<p>Select a user to assign plan(s) to them.</p>

</div>

{% if confirm is sameas false %}
<div class="card mx-auto my-3 py-3 col-md-7">
<h3 class="card-title mx-auto">Are you sure?</h3>
<div class="mx-auto">
<a href="{{ url_for('admin.delete_choice_group', id=choice_group.id) }}"
class="btn btn-danger mx-3 px-5" role="button">
Yes
</a>
<a href="{{ url_for('admin.list_choice_groups', cancel=1) }}"
class="btn btn-success mx-3 px-5" role="button">
No
</a>
</div>
</div>
{% else %}
<table class="table table-hover table-scroll">
<thead>
<th>Title</th>
<th></th>
<th></th>
<th></th>
<th></th>
</thead>
{% for user in users %}
<tr>
<td>
{{ user.email}}
</td>
<td>
<a href="{# url_for('admin.choice_group_assign_plan', choice_group_id=choice_group.id) #}"
class="btn btn-success btn-block" style="display: inline-block" role="button">
Assign Plan(s)
</a>
</td>
</tr>
{% endfor %}
</table>
{% endif %}

</div><!--end container-->
</div><!--end section-->
</main>

{% endblock body %}
1 change: 1 addition & 0 deletions subscribie/blueprints/admin/templates/admin/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ <h2 class="text-center text-dark mb-3">Manage My Shop</h2>
<div class="container">
<div class="card px-3 py-3 my-3">
<h3 class="card-title">Checklist</h3>
<a href="{{ url_for("admin.assign_managers_to_plan") }}">Assign managers to plan</a>
<p class="card-subtitle mb-3 text-muted">
Make sure everything's in order. If tasks appear below, then
you'll need to complete them to get the most out of your shop.
Expand Down
22 changes: 21 additions & 1 deletion subscribie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,16 @@ class Company(database.Model):
database.Column("plan_id", database.Integer, ForeignKey("plan.id")),
)


"""
Some shop owners want/need to assign managers (users) to
plans. For example large clubs or membership organisations which
assign a 'manager' to one or more plans.
The plan_user_associations table begins to make possible the
assignment of Users to Plans. Recall that Users (see class User
in models.py) is a shop owner (admin) which may login to the
Subscribie application.
"""
association_table_plan_to_price_lists = database.Table(
"plan_price_list_associations",
database.Column(
Expand All @@ -595,6 +604,12 @@ class Company(database.Model):
),
)

association_table_plan_to_users = database.Table(
"plan_user_associations",
database.Column("plan_uuid", database.String, ForeignKey("plan.uuid")),
database.Column("user_id", database.String, ForeignKey("user.id")),
)


class INTERVAL_UNITS(Enum):
DAILY = _("daily")
Expand Down Expand Up @@ -656,6 +671,11 @@ class Plan(database.Model, HasArchived):
price_lists = relationship(
"PriceList", secondary=association_table_plan_to_price_lists
)
managers = relationship(
"User",
secondary=association_table_plan_to_users,
backref=database.backref("plans", lazy="dynamic"),
)

def getPrice(self, currency):
"""Returns a tuple of sell_price and interval_amount of the plan for
Expand Down

0 comments on commit a16a621

Please sign in to comment.