Ejemplo n.º 1
0
class RHCreateRoomBlocking(RHRoomBookingBase):
    @use_args({
        'room_ids': fields.List(fields.Int(), missing=[]),
        'start_date': fields.Date(required=True),
        'end_date': fields.Date(required=True),
        'reason': fields.Str(required=True),
        'allowed': PrincipalList(allow_groups=True, required=True),
    })
    def _process(self, args):
        blocking = create_blocking(created_by=session.user, **args)
        return jsonify(blockings_schema.dump(blocking, many=False))
Ejemplo n.º 2
0
class RHUpdateRoomBlocking(RHRoomBookingBase):
    def _check_access(self):
        RHRoomBookingBase._check_access(self)
        if not self.blocking.can_edit(session.user):
            raise Forbidden

    def _process_args(self):
        self.blocking = Blocking.get_or_404(request.view_args['blocking_id'])

    @use_args({
        'room_ids': fields.List(fields.Int(), required=True),
        'reason': fields.Str(required=True),
        'allowed': PrincipalList(allow_groups=True, required=True),
    })
    def _process(self, args):
        update_blocking(self.blocking, **args)
        return jsonify(blockings_schema.dump(self.blocking, many=False))
Ejemplo n.º 3
0
class RHPrincipals(RHProtected):
    """Resolve principal identifiers to their actual objects.

    This is intended for PrincipalListField which needs to be able
    to resolve the identifiers provided to it to something more
    human-friendly.
    """
    def _serialize_principal(self, principal):
        if principal.principal_type == PrincipalType.user:
            return {
                'identifier':
                principal.identifier,
                'user_id':
                principal.id,
                'group':
                False,
                'name':
                principal.display_full_name,
                'detail':
                ('{} ({})'.format(principal.email, principal.affiliation)
                 if principal.affiliation else principal.email)
            }
        elif principal.principal_type == PrincipalType.local_group:
            return {
                'identifier': principal.identifier,
                'group': True,
                'name': principal.name
            }
        elif principal.principal_type == PrincipalType.multipass_group:
            return {
                'identifier': principal.identifier,
                'group': True,
                'name': principal.name,
                'detail': principal.provider_title
            }

    @use_kwargs({'values': PrincipalList(allow_groups=True, missing=[])})
    def _process(self, values):
        return jsonify(
            {x.identifier: self._serialize_principal(x)
             for x in values})
Ejemplo n.º 4
0
class RHAddEventRoleMembers(RHManageEventRole):
    """Add users to an event role."""
    @use_kwargs({
        'users':
        PrincipalList(required=True, allow_external_users=True),
    })
    def _process(self, users):
        for user in users - self.role.members:
            self.role.members.add(user)
            logger.info('User %r added to role %r by %r', user, self.role,
                        session.user)
            self.event.log(EventLogRealm.management,
                           LogKind.positive,
                           'Roles',
                           f'Added user to role "{self.role.name}"',
                           session.user,
                           data={
                               'Name': user.full_name,
                               'Email': user.email
                           })
        return jsonify_data(html=_render_role(self.role, collapsed=False))