Ejemplo n.º 1
0
 def _process(self):
     form = RoleForm(event=self.event, color=self._get_color())
     if form.validate_on_submit():
         role = EventRole(event=self.event)
         form.populate_obj(role)
         db.session.flush()
         logger.info('Event role %r created by %r', role, session.user)
         self.event.log(EventLogRealm.management, EventLogKind.positive, 'Roles',
                        'Added role: "{}"'.format(role.name), session.user)
         return jsonify_data(html=_render_roles(self.event), role=serialize_role(role))
     return jsonify_form(form)
Ejemplo n.º 2
0
def serialize_principal(principal):
    if principal.principal_type == PrincipalType.email:
        return serialize_email_principal(principal)
    elif principal.principal_type == PrincipalType.network:
        return serialize_ip_network_group(principal)
    elif principal.principal_type == PrincipalType.user:
        return serialize_user(principal)
    elif principal.principal_type == PrincipalType.event_role:
        return serialize_role(principal)
    elif principal.is_group:
        return serialize_group(principal)
    else:
        raise ValueError('Invalid principal: {} ({})'.format(principal, principal.principal_type))
Ejemplo n.º 3
0
def serialize_principal(principal):
    if principal.principal_type == PrincipalType.email:
        return serialize_email_principal(principal)
    elif principal.principal_type == PrincipalType.network:
        return serialize_ip_network_group(principal)
    elif principal.principal_type == PrincipalType.user:
        return serialize_user(principal)
    elif principal.principal_type == PrincipalType.event_role:
        return serialize_role(principal)
    elif principal.is_group:
        return serialize_group(principal)
    else:
        raise ValueError('Invalid principal: {} ({})'.format(principal, principal.principal_type))
Ejemplo n.º 4
0
 def _process(self):
     form = RoleForm(event=self.event, color=self._get_color())
     if form.validate_on_submit():
         role = EventRole(event=self.event)
         form.populate_obj(role)
         db.session.flush()
         logger.info('Event role %r created by %r', role, session.user)
         self.event.log(EventLogRealm.management, EventLogKind.positive,
                        'Roles', 'Added role: "{}"'.format(role.name),
                        session.user)
         return jsonify_data(html=_render_roles(self.event),
                             role=serialize_role(role))
     return jsonify_form(form)
Ejemplo n.º 5
0
 def roles(self):
     return [serialize_role(role) for role in sorted(self.get_form().event.roles, key=attrgetter('code'))]
Ejemplo n.º 6
0
 def roles(self):
     return [serialize_role(role) for role in sorted(self.event.roles, key=attrgetter('code'))]
Ejemplo n.º 7
0
 def event_roles(self):
     return [
         serialize_role(role, legacy=False)
         for role in sorted(self.event.roles, key=attrgetter('code'))
     ]