diff --git a/migrations/versions/c4c7bbe1acdc_feature_can_assign_users_to_plans_.py b/migrations/versions/c4c7bbe1acdc_feature_can_assign_users_to_plans_.py new file mode 100644 index 00000000..8e411507 --- /dev/null +++ b/migrations/versions/c4c7bbe1acdc_feature_can_assign_users_to_plans_.py @@ -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 diff --git a/subscribie/blueprints/admin/__init__.py b/subscribie/blueprints/admin/__init__.py index d2cdaf16..7c675066 100644 --- a/subscribie/blueprints/admin/__init__.py +++ b/subscribie/blueprints/admin/__init__.py @@ -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 @@ -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", @@ -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(): diff --git a/subscribie/blueprints/admin/templates/admin/dashboard.html b/subscribie/blueprints/admin/templates/admin/dashboard.html index be41b8cb..d103cca0 100644 --- a/subscribie/blueprints/admin/templates/admin/dashboard.html +++ b/subscribie/blueprints/admin/templates/admin/dashboard.html @@ -544,6 +544,10 @@

Templates

href="{{ url_for('admin.change_thank_you_url') }}"> Change Thank You Page/Payment Successful Page URL + + Assign Manager(s) to plans feature (enable/disable) + diff --git a/subscribie/blueprints/admin/templates/admin/settings/feature_assign_users_to_plans_enable_disable.html b/subscribie/blueprints/admin/templates/admin/settings/feature_assign_users_to_plans_enable_disable.html new file mode 100644 index 00000000..6e37f3ca --- /dev/null +++ b/subscribie/blueprints/admin/templates/admin/settings/feature_assign_users_to_plans_enable_disable.html @@ -0,0 +1,54 @@ +{% extends "admin/layout.html" %} +{% block title %} {{ _('Assign Manager(s) to plans feature enable/disable') }} {% endblock %} + +{% block body %} + +

{{ _('Assign Manager(s) to plans feature enable/disable') }}

+ +
+ +
+ +
+
+
+ +
+
+

{{ _('Assign Manager(s) to plans feature') }}

+

{{ _('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.') }}

+ +
+
+
+ + +
+
+
+ + +
+
+
+ +
+
+ +
+ +
+
+
+ + + +{% endblock %} diff --git a/subscribie/blueprints/admin/templates/admin/subscribers.html b/subscribie/blueprints/admin/templates/admin/subscribers.html index cbebcf68..32b4f83a 100644 --- a/subscribie/blueprints/admin/templates/admin/subscribers.html +++ b/subscribie/blueprints/admin/templates/admin/subscribers.html @@ -37,7 +37,7 @@

Search...

{% endif %} - {% if user.plans | length == 0 %} + {% if user.plans | length == 0 and settings.feature_can_assign_users_to_plans %}
You don't currently have any plans assigned to your user. To assign plans to your user login, Edit an existing plan or Create a new plan and click 'Managers' when editing or adding diff --git a/subscribie/models.py b/subscribie/models.py index 404b8736..5756a36a 100644 --- a/subscribie/models.py +++ b/subscribie/models.py @@ -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):