Skip to content

Commit

Permalink
#1281 wip draftPlan.users.extend(managers)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsimpson committed Mar 4, 2024
1 parent 73b2169 commit 6ce6447
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""feature_can_assign_users_to_plans settings
Revision ID: c4c7bbe1acdc
Revises: ac23e0d75b27
Create Date: 2024-02-26 09:06:42.508631
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "c4c7bbe1acdc"
down_revision = "ac23e0d75b27"
branch_labels = None
depends_on = None


def upgrade():
with op.batch_alter_table("setting", schema=None) as batch_op:
batch_op.add_column(
sa.Column(
"feature_can_assign_users_to_plans",
sa.Boolean(),
nullable=True,
default=False,
)
)


def downgrade():
pass
36 changes: 34 additions & 2 deletions subscribie/blueprints/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ def add_plan():
managers.append(user)

draftPlan = Plan()
draftPlan.managers.extend(managers)
draftPlan.users.extend(managers)
database.session.add(draftPlan)
plan_requirements = PlanRequirements()
draftPlan.requirements = plan_requirements
Expand Down Expand Up @@ -915,7 +915,11 @@ def user_assign_to_plans(user_id):
return redirect(url_for("admin.assign_managers_to_plan"))

plans = Plan.query.execution_options(include_archived=True).all()
user = User.query.execution_options(include_archived=True).where(User.id == user_id).first()
user = (
User.query.execution_options(include_archived=True)
.where(User.id == user_id)
.first()
)

return render_template(
"admin/user_assign_plan.html",
Expand Down Expand Up @@ -2230,6 +2234,34 @@ def donations_enabled_settings():
return render_template("admin/settings/donations_enabled.html", settings=settings)


@admin.route("/assign-users-to-plans-feature-toggle", methods=["GET", "POST"])
@login_required
def feature_assign_users_to_plans_enable_disable():
settings = Setting.query.first() # Get current shop settings
if settings.feature_can_assign_users_to_plans is None:
settings.feature_can_assign_users_to_plans = False
database.session.commit()

if request.method == "POST":
if int(request.form.get("feature_can_assign_users_to_plans", 0)) == 1:
settings.feature_can_assign_users_to_plans = 1
effect = "enabled"
else:
settings.feature_can_assign_users_to_plans = 0
effect = "disabled"
flash(f"Assign managers to plan feature has been {effect}")
database.session.commit()
return redirect(
url_for(
"admin.feature_assign_users_to_plans_enable_disable", settings=settings
)
)
return render_template(
"admin/settings/feature_assign_users_to_plans_enable_disable.html",
settings=settings,
)


@admin.route("/api-keys", methods=["GET", "POST"])
@login_required
def show_api_keys():
Expand Down
4 changes: 4 additions & 0 deletions subscribie/blueprints/admin/templates/admin/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@ <h3 class="card-title">Templates</h3>
href="{{ url_for('admin.change_thank_you_url') }}">
Change Thank You Page/Payment Successful Page URL
</a>
<a class="btn btn-success btn-block"
href="{{ url_for('admin.feature_assign_users_to_plans_enable_disable') }}">
Assign Manager(s) to plans feature (enable/disable)
</a>

</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{% extends "admin/layout.html" %}
{% block title %} {{ _('Assign Manager(s) to plans feature enable/disable') }} {% endblock %}

{% block body %}

<h2 class="text-center text-dark mb-3">{{ _('Assign Manager(s) to plans feature enable/disable') }}</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 active" aria-current="page">{{ _('Assign Manager(s) to plans feature enable/disable') }}</li>
</ul>
</div>

<main>
<div class="section">
<div class="container">

<div class="row row-cols-1 row-cols-md-2">
<div class="col-md-7">
<h2>{{ _('Assign Manager(s) to plans feature') }}</h2>
<p>{{ _('Enable this feature to allow you to assign admins to manage plans. If you have a lot of plans/subscribers, this makes it easier to divide the work of managing groups of subscribers. This is especially useful for large clubs and membership organisations where you might not know all of the subscribers in your organisaton, but other coworkers know and manage them.') }}</p>

<form action="" method="POST" action="/">
<div class="form-group">
<div class="form-check">
<input class="form-check-input" type="radio" name="feature_can_assign_users_to_plans" value="1" id="yes" {% if settings.feature_can_assign_users_to_plans is sameas True %}checked {% endif %}>
<label class="form-check-label" for="yes">
{{ _('Enable') }}
</label>
</div>
<br />
<div class="form-check">
<input class="form-check-input" type="radio" name="feature_can_assign_users_to_plans" value="0" id="no" {% if settings.feature_can_assign_users_to_plans is sameas False %}checked {% endif %}>
<label class="form-check-label" for="no">
{{ _('Disable') }}
</label>
</div>
</div>
<br />
<button type="submit" class="btn btn-primary btn-block mb-3">{{ _('Save') }}</button>
</form>
</div>

</div>

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



{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h4>Search...</h4>
</div>
{% endif %}

{% if user.plans | length == 0 %}
{% if user.plans | length == 0 and settings.feature_can_assign_users_to_plans %}
<div class="alert alert-warning">
You don't currently have any plans assigned to your user. To assign plans to your user login,
<a href="{{ url_for('admin.edit') }}">Edit an existing plan</a> or <a href="{{ url_for('admin.add_plan') }}">Create a new plan</a> and click 'Managers' when editing or adding
Expand Down
3 changes: 3 additions & 0 deletions subscribie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,9 @@ class Setting(database.Model):
api_key_secret_test = database.Column(database.String(), default=None)
donations_enabled = database.Column(database.Boolean(), default=False)
custom_thank_you_url = database.Column(database.String(), default=None)
feature_can_assign_users_to_plans = database.Column(
database.Boolean(), default=False
)


class File(database.Model):
Expand Down

0 comments on commit 6ce6447

Please sign in to comment.