Exemplo n.º 1
0
class RHUsersAdminMergeCheck(RHAdminBase):
    @use_kwargs({
        'source': Principal(allow_external_users=True, required=True),
        'target': Principal(allow_external_users=True, required=True),
    }, location='query')
    def _process(self, source, target):
        errors, warnings = _get_merge_problems(source, target)
        return jsonify(errors=errors, warnings=warnings, source=serialize_user(source), target=serialize_user(target))
Exemplo n.º 2
0
class RoomUpdateArgsSchema(mm.Schema):
    verbose_name = fields.String(allow_none=True)
    site = fields.String(allow_none=True)
    building = fields.String(validate=lambda x: x is not None)
    floor = fields.String(validate=lambda x: x is not None)
    number = fields.String(validate=lambda x: x is not None)
    longitude = fields.Float(allow_none=True)
    latitude = fields.Float(allow_none=True)
    is_reservable = fields.Boolean(allow_none=True)
    reservations_need_confirmation = fields.Boolean(allow_none=True)
    notification_emails = fields.List(fields.Email())
    notification_before_days = fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True)
    notification_before_days_weekly = fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True)
    notification_before_days_monthly = fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True)
    notifications_enabled = fields.Boolean()
    end_notification_daily = fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True)
    end_notification_weekly = fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True)
    end_notification_monthly = fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True)
    end_notifications_enabled = fields.Boolean()
    booking_limit_days = fields.Int(validate=lambda x: x >= 1, allow_none=True)
    owner = Principal(validate=lambda x: x is not None, allow_none=True)
    key_location = fields.String()
    telephone = fields.String()
    capacity = fields.Int(validate=lambda x: x >= 1)
    division = fields.String(allow_none=True)
    surface_area = fields.Int(validate=lambda x: x >= 0, allow_none=True)
    max_advance_days = fields.Int(validate=lambda x: x >= 1, allow_none=True)
    comments = fields.String()
    acl_entries = PrincipalPermissionList(RoomPrincipal)
    protection_mode = EnumField(ProtectionMode)
Exemplo n.º 3
0
class RHUpdateRoom(RHRoomAdminBase):
    @use_args({
        'verbose_name': fields.Str(allow_none=True),
        'site': fields.Str(allow_none=True),
        'building': fields.String(validate=lambda x: x is not None),
        'floor': fields.String(validate=lambda x: x is not None),
        'number': fields.String(validate=lambda x: x is not None),
        'longitude': fields.Float(allow_none=True),
        'latitude': fields.Float(allow_none=True),
        'is_reservable': fields.Bool(allow_none=True),
        'reservations_need_confirmation': fields.Bool(allow_none=True),
        'notification_emails': fields.List(fields.Email()),
        'notification_before_days': fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True),
        'notification_before_days_weekly': fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True),
        'notification_before_days_monthly': fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True),
        'notifications_enabled': fields.Bool(),
        'end_notification_daily': fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True),
        'end_notification_weekly': fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True),
        'end_notification_monthly': fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True),
        'end_notifications_enabled': fields.Bool(),
        'booking_limit_days': fields.Int(validate=lambda x: x >= 1, allow_none=True),
        'owner': Principal(validate=lambda x: x is not None, allow_none=True),
        'key_location': fields.Str(),
        'telephone': fields.Str(),
        'capacity': fields.Int(validate=lambda x: x >= 1),
        'division': fields.Str(allow_none=True),
        'surface_area': fields.Int(validate=lambda x: x >= 0, allow_none=True),
        'max_advance_days': fields.Int(validate=lambda x: x >= 1, allow_none=True),
        'comments': fields.Str(),
    })
    def _process(self, args):
        update_room(self.room, args)
        RHRoomsPermissions._jsonify_user_permissions.clear_cached(session.user)
        return jsonify(room_update_schema.dump(self.room, many=False))
Exemplo n.º 4
0
class RHRegistrationCreate(RHManageRegFormBase):
    """Create new registration (management area)."""

    @use_kwargs({
        'user': Principal(allow_external_users=True, missing=None),
    }, location='query')
    def _get_user_data(self, user):
        if user is None:
            return {}
        user_data = {t.name: getattr(user, t.name, None) for t in PersonalDataType}
        user_data['title'] = get_title_uuid(self.regform, user_data['title'])
        return user_data

    def _process(self):
        form = make_registration_form(self.regform, management=True)()
        if form.validate_on_submit():
            data = form.data
            session['registration_notify_user_default'] = notify_user = data.pop('notify_user', False)
            create_registration(self.regform, data, management=True, notify_user=notify_user)
            flash(_('The registration was created.'), 'success')
            return redirect(url_for('.manage_reglist', self.regform))
        elif form.is_submitted():
            # not very pretty but usually this never happens thanks to client-side validation
            for error in form.error_list:
                flash(error, 'error')
        return WPManageRegistration.render_template('display/regform_display.html', self.event,
                                                    regform=self.regform,
                                                    sections=get_event_section_data(self.regform),
                                                    post_url=url_for('.create_registration', self.regform),
                                                    user_data=self._get_user_data(),
                                                    invitation=None,
                                                    registration=None,
                                                    management=True,
                                                    login_required=False,
                                                    is_restricted_access=False)
Exemplo n.º 5
0
class RoomUpdateSchema(RoomSchema):
    owner = Principal()

    class Meta(RoomSchema.Meta):
        fields = RoomSchema.Meta.fields + (
            'notification_before_days', 'notification_before_days_weekly',
            'owner', 'notification_before_days_monthly',
            'notifications_enabled', 'end_notification_daily',
            'end_notification_weekly', 'end_notification_monthly',
            'end_notifications_enabled', 'verbose_name', 'site',
            'notification_emails')
Exemplo n.º 6
0
class RoomUpdateSchema(RoomSchema):
    owner = Principal()
    acl_entries = PrincipalPermissionList(RoomPrincipal)
    protection_mode = EnumField(ProtectionMode)

    class Meta(RoomSchema.Meta):
        fields = RoomSchema.Meta.fields + ('notification_before_days', 'notification_before_days_weekly', 'owner',
                                           'notification_before_days_monthly', 'notifications_enabled',
                                           'end_notification_daily', 'end_notification_weekly',
                                           'end_notification_monthly', 'end_notifications_enabled',
                                           'verbose_name', 'site', 'notification_emails', 'booking_limit_days',
                                           'acl_entries', 'protection_mode')
Exemplo n.º 7
0
class RHAssignEditor(RHEditablesBase):
    @use_kwargs({
        'editor': Principal(required=True)
    })
    def _process_args(self, editor):
        RHEditablesBase._process_args(self)
        if (not self.event.can_manage(editor, self.editable_type.editor_permission)
                and not self.event.can_manage(editor, 'editing_manager')):
            raise Forbidden(_('This user is not an editor of the {} type').format(self.editable_type.name))

        self.editor = editor

    def _process(self):
        editables = [e for e in self.editables if e.editor != self.editor]
        for editable in editables:
            assign_editor(editable, self.editor)
        return EditableBasicSchema(many=True).jsonify(editables)
Exemplo n.º 8
0
class CreateBookingSchema(mm.Schema):
    start_dt = fields.DateTime(required=True)
    end_dt = fields.DateTime(required=True)
    repeat_frequency = EnumField(RepeatFrequency, required=True)
    repeat_interval = fields.Int(load_default=0, validate=lambda x: x >= 0)
    room_id = fields.Int(required=True)
    booked_for_user = Principal(data_key='user', allow_external_users=True)
    booking_reason = fields.String(data_key='reason', validate=validate.Length(min=3), required=True)
    is_prebooking = fields.Bool(load_default=False)
    link_type = EnumField(LinkType)
    link_id = fields.Int()
    link_back = fields.Bool(load_default=False)
    admin_override_enabled = fields.Bool(load_default=False)

    @validates_schema(skip_on_field_errors=True)
    def validate_dts(self, data, **kwargs):
        if data['start_dt'] >= data['end_dt']:
            raise ValidationError(_('Booking cannot end before it starts'))
Exemplo n.º 9
0
class RHRegistrationCreate(RHManageRegFormBase):
    """Create new registration (management area)."""
    @use_kwargs(
        {
            'user': Principal(allow_external_users=True, load_default=None),
        },
        location='query')
    def _get_user_data(self, user):
        return get_user_data(self.regform, user)

    def _process_POST(self):
        if self.regform.is_purged:
            raise Forbidden(
                _('Registration is disabled due to an expired retention period'
                  ))
        schema = make_registration_schema(self.regform, management=True)()
        form = parser.parse(schema)
        session['registration_notify_user_default'] = notify_user = form.pop(
            'notify_user', False)
        create_registration(self.regform,
                            form,
                            management=True,
                            notify_user=notify_user)
        flash(_('The registration was created.'), 'success')
        return jsonify({'redirect': url_for('.manage_reglist', self.regform)})

    def _process_GET(self):
        user_data = self._get_user_data()
        initial_values = get_initial_form_values(self.regform,
                                                 management=True) | user_data
        form_data = get_flat_section_submission_data(self.regform,
                                                     management=True)
        return WPManageRegistration.render_template(
            'display/regform_display.html',
            self.event,
            regform=self.regform,
            form_data=form_data,
            initial_values=initial_values,
            invitation=None,
            registration=None,
            management=True,
            login_required=False,
            is_restricted_access=False)
Exemplo n.º 10
0
    'notification_before_days_monthly':
    fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True),
    'notifications_enabled':
    fields.Bool(),
    'end_notification_daily':
    fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True),
    'end_notification_weekly':
    fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True),
    'end_notification_monthly':
    fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True),
    'end_notifications_enabled':
    fields.Bool(),
    'booking_limit_days':
    fields.Int(validate=lambda x: x >= 1, allow_none=True),
    'owner':
    Principal(validate=lambda x: x is not None, allow_none=True),
    'key_location':
    fields.Str(),
    'telephone':
    fields.Str(),
    'capacity':
    fields.Int(validate=lambda x: x >= 1),
    'division':
    fields.Str(allow_none=True),
    'surface_area':
    fields.Int(validate=lambda x: x >= 0, allow_none=True),
    'max_advance_days':
    fields.Int(validate=lambda x: x >= 1, allow_none=True),
    'comments':
    fields.Str(),
}