-
Notifications
You must be signed in to change notification settings - Fork 131
chore(ui/permissions): hide “Create Organizer” in admin tickets page, allow creation in common organizers view #890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: enext
Are you sure you want to change the base?
Changes from 5 commits
b214ec9
1c07d83
896f553
85d21d8
b800de5
cbb2c93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,15 @@ | ||
| from urllib.parse import quote | ||
|
|
||
| from django.core.exceptions import PermissionDenied | ||
| from django.db.models import Q | ||
| from django.shortcuts import redirect | ||
| from django.urls import reverse | ||
| from django.utils.translation import gettext as _ | ||
|
|
||
| from eventyay.base.models import Organizer | ||
| from eventyay.base.models.organizer import OrganizerBillingModel | ||
| from eventyay.base.settings import GlobalSettingsObject | ||
|
|
||
|
|
||
| def current_url(request): | ||
| if request.GET: | ||
|
|
@@ -157,3 +162,83 @@ class StaffMemberRequiredMixin: | |
| def as_view(cls, **initkwargs): | ||
| view = super(StaffMemberRequiredMixin, cls).as_view(**initkwargs) | ||
| return staff_member_required()(view) | ||
|
|
||
|
|
||
| class OrganizerCreationPermissionMixin: | ||
| """ | ||
| Mixin to check if a user has permission to create organizers. | ||
| Can be used in any view that needs to check organizer creation permissions. | ||
| """ | ||
|
|
||
| def _can_create_organizer(self, user): | ||
| """ | ||
| Check if the user has permission to create an organizer. | ||
|
|
||
| Permission precedence (highest to lowest): | ||
| 1. System admins (staff with active session) - always allowed | ||
| 2. Default when both settings are None - allow all users (permissive default) | ||
| 3. allow_all_users_create_organizer=True - allow all authenticated users | ||
| 4. allow_payment_users_create_organizer=True - allow users with payment info | ||
| 5. Both False - deny (admin only) | ||
|
|
||
| Note: If allow_all_users=True, it takes precedence over allow_payment_users | ||
| (no need to check payment info if all users are already allowed). | ||
|
|
||
| Args: | ||
| user: The user to check permissions for | ||
|
|
||
| Returns: | ||
| bool: True if user can create organizers, False otherwise | ||
| """ | ||
| # System admins can always create organizers | ||
| if user.has_active_staff_session(self.request.session.session_key): | ||
| return True | ||
|
|
||
| # Get global settings | ||
| gs = GlobalSettingsObject() | ||
| allow_all_users = gs.settings.get('allow_all_users_create_organizer', None, as_type=bool) | ||
| allow_payment_users = gs.settings.get('allow_payment_users_create_organizer', None, as_type=bool) | ||
|
|
||
| # If neither option is explicitly set, default to allowing all users (permissive default) | ||
| if allow_all_users is None and allow_payment_users is None: | ||
| return True | ||
|
|
||
| # If all users are allowed (takes precedence over payment check) | ||
| if allow_all_users: | ||
| return True | ||
|
|
||
| # If users with payment information are allowed | ||
| if allow_payment_users: | ||
| return self._user_has_payment_info(user) | ||
|
|
||
| # By default, deny access if settings are explicitly set to False | ||
| return False | ||
|
|
||
| def _user_has_payment_info(self, user): | ||
| """ | ||
| Check if the user has valid payment information on file. | ||
|
|
||
| This checks if any of the user's organizers have billing records with payment method setup. | ||
| Checks for: | ||
| - stripe_customer_id: Indicates Stripe customer account | ||
| - stripe_payment_method_id: Indicates saved payment method | ||
|
|
||
| Args: | ||
| user: The user to check payment info for | ||
|
|
||
| Returns: | ||
| bool: True if user has payment info, False otherwise | ||
| """ | ||
| # Get all organizers where the user is a team member | ||
| user_organizers = Organizer.objects.filter( | ||
| teams__members=user | ||
| ).distinct() | ||
|
|
||
| # Single query to check if any billing record has payment info | ||
| # Check for either stripe_customer_id OR stripe_payment_method_id | ||
| return OrganizerBillingModel.objects.filter( | ||
| organizer__in=user_organizers | ||
| ).filter( | ||
| (Q(stripe_customer_id__isnull=False) & ~Q(stripe_customer_id='')) | | ||
| (Q(stripe_payment_method_id__isnull=False) & ~Q(stripe_payment_method_id='')) | ||
| ).exists() | ||
|
Comment on lines
+232
to
+244
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The help texts for the two organizer creation permission settings don't explain how they interact when both are enabled or what takes precedence. Consider updating the help texts to clarify:
For example:
allow_all_users_create_organizer: "If enabled, all registered users will be allowed to create organizers. This takes precedence over the payment information requirement below."allow_payment_users_create_organizer: "If enabled (and 'All registered users' is disabled), only users with valid payment information on file will be allowed to create organizers."