class CategoryProtectionForm(IndicoForm): _event_creation_fields = ('event_creation_restricted', 'event_creation_notification_emails') permissions = PermissionsField(_('Permissions'), object_type='category') protection_mode = IndicoProtectionField( _('Protection mode'), protected_object=lambda form: form.protected_object) own_no_access_contact = StringField( _('No access contact'), description=_( 'Contact information shown when someone lacks access to the ' 'category')) visibility = SelectField( _('Event visibility'), [Optional()], coerce=lambda x: None if x == '' else int(x), description= _('''From which point in the category tree contents will be visible from ''' '''(number of categories upwards). Applies to "Today's events" and ''' '''Calendar. If the category is moved, this number will be preserved.''' )) event_creation_restricted = BooleanField( _('Restricted event creation'), widget=SwitchWidget(), description=_('Whether the event creation should be restricted ' 'to a list of specific persons')) def __init__(self, *args, **kwargs): self.protected_object = self.category = kwargs.pop('category') super().__init__(*args, **kwargs) self._init_visibility() def _init_visibility(self): self.visibility.choices = get_visibility_options(self.category, allow_invisible=False) # Check if category visibility would be affected by any of the parents real_horizon = self.category.real_visibility_horizon own_horizon = self.category.own_visibility_horizon if real_horizon and real_horizon.is_descendant_of(own_horizon): self.visibility.warning = _( "This category's visibility is currently limited by that of '{}'." ).format(real_horizon.title) def validate_permissions(self, field): for principal_fossil, permissions in field.data: principal = principal_from_identifier( principal_fossil['identifier'], allow_groups=True, allow_networks=True, allow_category_roles=True, category_id=self.category.id) if isinstance(principal, IPNetworkGroup ) and set(permissions) - {READ_ACCESS_PERMISSION}: msg = _('IP networks cannot have management permissions: {}' ).format(principal.name) raise ValidationError(msg) if FULL_ACCESS_PERMISSION in permissions and len(permissions) != 1: # when full access permission is set, discard rest of permissions permissions[:] = [FULL_ACCESS_PERMISSION]
class EventProtectionForm(IndicoForm): permissions = PermissionsField(_("Permissions"), object_type='event') protection_mode = IndicoProtectionField(_('Protection mode'), protected_object=lambda form: form.protected_object, acl_message_url=lambda form: url_for('event_management.acl_message', form.protected_object)) access_key = IndicoPasswordField(_('Access key'), toggle=True, description=_('It is more secure to use only the ACL and not set an access key. ' '<strong>It will have no effect if the event is not ' 'protected</strong>')) own_no_access_contact = StringField(_('No access contact'), description=_('Contact information shown when someone lacks access to the ' 'event')) visibility = SelectField(_("Visibility"), [Optional()], coerce=lambda x: None if x == '' else int(x), description=_("""From which point in the category tree this event will be visible from """ """(number of categories upwards). Applies to "Today's events", """ """Calendar. If the event is moved, this number will be preserved. """ """The "Invisible" option will also hide the event from the category's """ """event list except for managers.""")) public_regform_access = BooleanField(_('Public registration'), widget=SwitchWidget(), description=_('Allow users who cannot access the event to register. This will ' 'expose open registration forms to anyone with a link to the ' 'event, so you can let users register without giving access ' 'to anything else in your event.')) priv_fields = set() def __init__(self, *args, **kwargs): self.protected_object = self.event = kwargs.pop('event') super().__init__(*args, **kwargs) self._init_visibility(self.event) def _get_event_own_visibility_horizon(self, event): if self.visibility.data is None: # unlimited return Category.get_root() elif self.visibility.data == 0: # invisible return None else: return event.category.nth_parent(self.visibility.data - 1) def _init_visibility(self, event): self.visibility.choices = get_visibility_options(event, allow_invisible=True) # Check if event visibility would be affected by any of the categories real_horizon = event.category.real_visibility_horizon own_horizon = self._get_event_own_visibility_horizon(event) if own_horizon and real_horizon and real_horizon.is_descendant_of(own_horizon): self.visibility.warning = _("This event's visibility is currently limited by that of '{}'.").format( real_horizon.title) def validate_permissions(self, field): except_msg = check_permissions(self.event, field, allow_networks=True, allow_registration_forms=True) if except_msg: raise ValidationError(except_msg) @classmethod def _create_coordinator_priv_fields(cls): for name, title in sorted(COORDINATOR_PRIV_TITLES.items(), key=itemgetter(1)): setattr(cls, name, BooleanField(title, widget=SwitchWidget(), description=COORDINATOR_PRIV_DESCS[name])) cls.priv_fields.add(name)
class ContributionProtectionForm(IndicoForm): permissions = PermissionsField(_("Permissions"), object_type='contribution') protection_mode = IndicoProtectionField(_('Protection mode'), protected_object=lambda form: form.protected_object, acl_message_url=lambda form: url_for('contributions.acl_message', form.protected_object)) def __init__(self, *args, **kwargs): self.protected_object = contribution = kwargs.pop('contrib') self.event = contribution.event super(ContributionProtectionForm, self).__init__(*args, **kwargs) def validate_permissions(self, field): check_permissions(self.event, field)
class ContributionProtectionForm(IndicoForm): permissions = PermissionsField(_("Permissions"), object_type='contribution') protection_mode = IndicoProtectionField( _('Protection mode'), protected_object=lambda form: form.protected_object, acl_message_url=lambda form: url_for('contributions.acl_message', form. protected_object)) def __init__(self, *args, **kwargs): self.protected_object = contribution = kwargs.pop('contrib') self.event = contribution.event super().__init__(*args, **kwargs) def validate_permissions(self, field): except_msg = check_permissions(self.event, field, allow_registration_forms=True) if except_msg: raise ValidationError(except_msg)
class CategoryProtectionForm(IndicoForm): _event_creation_fields = ('event_creation_restricted', 'event_creation_notification_emails') permissions = PermissionsField(_("Permissions"), object_type='category') protection_mode = IndicoProtectionField( _('Protection mode'), protected_object=lambda form: form.protected_object) own_no_access_contact = StringField( _('No access contact'), description=_( 'Contact information shown when someone lacks access to the ' 'category')) visibility = SelectField( _("Event visibility"), [Optional()], coerce=lambda x: None if x == '' else int(x), description= _("""From which point in the category tree contents will be visible from """ """(number of categories upwards). Applies to "Today's events" and """ """Calendar. If the category is moved, this number will be preserved.""" )) event_creation_restricted = BooleanField( _('Restricted event creation'), widget=SwitchWidget(), description=_('Whether the event creation should be restricted ' 'to a list of specific persons')) def __init__(self, *args, **kwargs): self.protected_object = self.category = kwargs.pop('category') super(CategoryProtectionForm, self).__init__(*args, **kwargs) self._init_visibility() def _init_visibility(self): self.visibility.choices = get_visibility_options(self.category, allow_invisible=False) # Check if category visibility would be affected by any of the parents real_horizon = self.category.real_visibility_horizon own_horizon = self.category.own_visibility_horizon if real_horizon and real_horizon.is_descendant_of(own_horizon): self.visibility.warning = _( "This category's visibility is currently limited by that of '{}'." ).format(real_horizon.title)
class EventProtectionForm(IndicoForm): permissions = PermissionsField(_("Permissions")) protection_mode = IndicoProtectionField( _('Protection mode'), protected_object=lambda form: form.protected_object, acl_message_url=lambda form: url_for('event_management.acl_message', form.protected_object)) access_key = IndicoPasswordField( _('Access key'), toggle=True, description=_( 'It is more secure to use only the ACL and not set an access key. ' '<strong>It will have no effect if the event is not ' 'protected</strong>')) own_no_access_contact = StringField( _('No access contact'), description=_( 'Contact information shown when someone lacks access to the ' 'event')) visibility = SelectField( _("Visibility"), [Optional()], coerce=lambda x: None if x == '' else int(x), description= _("""From which point in the category tree this event will be visible from """ """(number of categories upwards). Applies to "Today's events" and """ """Calendar only. If the event is moved, this number will be preserved.""" )) priv_fields = set() def __init__(self, *args, **kwargs): self.protected_object = self.event = kwargs.pop('event') super(EventProtectionForm, self).__init__(*args, **kwargs) self._init_visibility(self.event) def _get_event_own_visibility_horizon(self, event): if self.visibility.data is None: # unlimited return Category.get_root() elif self.visibility.data == 0: # invisible return None else: return event.category.nth_parent(self.visibility.data - 1) def _init_visibility(self, event): self.visibility.choices = get_visibility_options(event, allow_invisible=True) # Check if event visibility would be affected by any of the categories real_horizon = event.category.real_visibility_horizon own_horizon = self._get_event_own_visibility_horizon(event) if own_horizon and real_horizon and real_horizon.is_descendant_of( own_horizon): self.visibility.warning = _( "This event's visibility is currently limited by that of '{}'." ).format(real_horizon.title) def validate_permissions(self, field): event = self.event for principal_fossil, permissions in field.data: principal = principal_from_fossil(principal_fossil, allow_emails=True, allow_networks=True, event=event) if isinstance(principal, IPNetworkGroup ) and set(permissions) - {READ_ACCESS_PERMISSION}: msg = _('IP networks cannot have management permissions: {}') raise ValidationError(msg.format(principal.name)) if FULL_ACCESS_PERMISSION in permissions and len(permissions) != 1: # when full access permission is set, discard rest of permissions permissions[:] = [FULL_ACCESS_PERMISSION] @classmethod def _create_coordinator_priv_fields(cls): for name, title in sorted(COORDINATOR_PRIV_TITLES.iteritems(), key=itemgetter(1)): setattr( cls, name, BooleanField(title, widget=SwitchWidget(), description=COORDINATOR_PRIV_DESCS[name])) cls.priv_fields.add(name)