Esempio n. 1
0
def accept_invite():
    token = request.json['data']['token']
    try:
        role_invite = RoleInvite.query.filter_by(hash=token).one()
    except NoResultFound:
        raise NotFoundError({'source': ''}, 'Role Invite Not Found')
    else:
        try:
            user = User.query.filter_by(email=role_invite.email).first()
        except NoResultFound:
            raise NotFoundError(
                {'source': ''}, 'User corresponding to role invite not Found'
            )
        try:
            role = Role.query.filter_by(name=role_invite.role_name).first()
        except NoResultFound:
            raise NotFoundError(
                {'source': ''}, 'Role corresponding to role invite not Found'
            )
        event = Event.query.filter_by(id=role_invite.event_id).first()
        uer = (
            UsersEventsRoles.query.filter_by(user=user)
            .filter_by(event=event)
            .filter_by(role=role)
            .first()
        )

        if not uer:
            if role_invite.role_name == 'owner':
                past_owner = UsersEventsRoles.query.filter_by(
                    event=event, role=role
                ).first()
                oldrole = Role.query.filter_by(name='organizer').first()
                prevuser = User.query.filter_by(id=past_owner.user_id).first()
                if past_owner:
                    delete_previous_uer(past_owner)
                    puer = UsersEventsRoles(user=prevuser, event=event, role=oldrole)
                    save_to_db(puer, 'User Event Role changed')
            role_invite.status = "accepted"
            save_to_db(role_invite, 'Role Invite Accepted')
            # reset the group of event
            event.group_id = None
            save_to_db(event, 'Group ID Removed')
            uer = UsersEventsRoles(user=user, event=event, role=role)
            save_to_db(uer, 'User Event Role Created')
            if not user.is_verified:
                user.is_verified = True
                save_to_db(user, 'User verified')

    return jsonify(
        {
            "email": user.email,
            "event": role_invite.event_id,
            "event_identifier": role_invite.event.identifier,
            "name": user.fullname if user.fullname else None,
            "role": uer.role.name,
        }
    )
Esempio n. 2
0
    def after_create_object(self, event, data, view_kwargs):
        """
        after create method to save roles for users and add the user as an accepted role(organizer)
        :param event:
        :param data:
        :param view_kwargs:
        :return:
        """
        role = Role.query.filter_by(name=ORGANIZER).first()
        user = User.query.filter_by(id=view_kwargs['user_id']).first()
        uer = UsersEventsRoles(user, event, role)
        save_to_db(uer, 'Event Saved')
        role_invite = RoleInvite(user.email,
                                 role.title_name,
                                 event.id,
                                 role.id,
                                 datetime.now(pytz.utc),
                                 status='accepted')
        save_to_db(role_invite, 'Organiser Role Invite Added')

        # create custom forms for compulsory fields of attendee form.
        create_custom_forms_for_attendees(event)

        if event.state == 'published' and event.schedule_published_on:
            start_export_tasks(event)
def test_group_post_access_allow(db, client, user, jwt):
    user.is_verified = True
    event = EventFactoryBasic()
    role, _ = get_or_create(Role, name='owner', title_name='Owner')
    UsersEventsRoles(user=user, event=event, role=role)

    db.session.commit()
    data = json.dumps({
        "data": {
            "type": "group",
            "relationships": {
                "events": {
                    "data": [{
                        "id": str(event.id),
                        "type": "event"
                    }]
                },
            },
            "attributes": {
                "name": "eventgp2"
            },
        }
    })

    response = client.post(
        f'/v1/groups',
        content_type='application/vnd.api+json',
        headers=jwt,
        data=data,
    )
    assert json.loads(
        response.data)['data']['attributes']['name'] == "eventgp2"
def accept_invite():
    token = request.json['data']['token']
    try:
        role_invite = RoleInvite.query.filter_by(hash=token).one()
    except NoResultFound:
        return NotFoundError({'source': ''}, 'Role Invite Not Found').respond()
    else:
        try:
            user = User.query.filter_by(email=role_invite.email).first()
        except NoResultFound:
            return NotFoundError({'source': ''}, 'User corresponding to role invite not Found').respond()
        try:
            role = Role.query.filter_by(name=role_invite.role_name).first()
        except NoResultFound:
            return NotFoundError({'source': ''}, 'Role corresponding to role invite not Found').respond()
        event = Event.query.filter_by(id=role_invite.event_id).first()
        uer = UsersEventsRoles.query.filter_by(user=user).filter_by(
            event=event).filter_by(role=role).first()
        if not uer:
            role_invite.status = "accepted"
            save_to_db(role_invite, 'Role Invite Accepted')
            uer = UsersEventsRoles(user, event, role)
            save_to_db(uer, 'User Event Role Created')
            if not user.is_verified:
                user.is_verified = True
                save_to_db(user, 'User verified')

    return jsonify({
        "email": user.email,
        "event": role_invite.event_id,
        "name": user.fullname if user.fullname else None
    })
def test_group_patch_access_deny(db, client, user, jwt):
    event = EventFactoryBasic()
    role, _ = get_or_create(Role, name='moderator', title_name='Moderator')
    UsersEventsRoles(user=user, event=event, role=role)
    db.session.commit()

    group = GroupFactory(user_id=user.id)
    db.session.commit()

    data = json.dumps({
        "data": {
            "type": "group",
            "id": str(group.id),
            "relationships": {
                "events": {
                    "data": [{
                        "id": str(event.id),
                        "type": "event"
                    }]
                },
            },
            "attributes": {
                "name": "eventgp1"
            },
        }
    })

    response = client.patch(
        f'/v1/groups/{group.id}',
        content_type='application/vnd.api+json',
        headers=jwt,
        data=data,
    )
    assert (json.loads(
        response.data)['errors'][0]['detail'] == 'Event owner access required')
Esempio n. 6
0
    def after_create_object(self, role_invite, data, view_kwargs):
        """
        after create object method for role invite links
        :param role_invite:
        :param data:
        :param view_kwargs:
        :return:
        """
        user = User.query.filter_by(email=role_invite.email).first()
        if 'status' in data and data['status'] == 'accepted':
            role = Role.query.filter_by(name=role_invite.role_name).first()
            event = Event.query.filter_by(id=role_invite.event_id).first()
            uer = UsersEventsRoles.query.filter_by(user=user).filter_by(
                event=event).filter_by(role=role).first()
            if not uer:
                uer = UsersEventsRoles(user, event, role)
                save_to_db(uer, 'Role Invite accepted')

        event = Event.query.filter_by(id=role_invite.event_id).first()
        frontend_url = get_settings()['frontend_url']
        link = "{}/events/{}/role-invites/{}" \
            .format(frontend_url, event.id, role_invite.hash)

        send_email_role_invite(role_invite.email, role_invite.role_name,
                               event.name, link)
        if user:
            send_notif_event_role(user, role_invite.role_name, event.name,
                                  link)
Esempio n. 7
0
    def after_create_object(self, event, data, view_kwargs):
        """
        after create method to save roles for users and add the user as an accepted role(owner and organizer)
        :param event:
        :param data:
        :param view_kwargs:
        :return:
        """
        user = User.query.filter_by(id=view_kwargs['user_id']).first()
        role = Role.query.filter_by(name=OWNER).first()
        uer = UsersEventsRoles(user=user, event=event, role=role)
        save_to_db(uer, 'Event Saved')
        role_invite = RoleInvite(
            email=user.email,
            role_name=role.title_name,
            event=event,
            role=role,
            status='accepted',
        )
        save_to_db(role_invite, 'Owner Role Invite Added')

        # create custom forms for compulsory fields of attendee form.
        create_custom_forms_for_attendees(event)

        if event.state == 'published' and event.schedule_published_on:
            start_export_tasks(event)

        if data.get('original_image_url'):
            start_image_resizing_tasks(event, data['original_image_url'])
def get_event(db, user=None):
    event = EventFactoryBasic(state='draft')
    if user:
        role, _ = get_or_create(Role, name='owner', title_name='Owner')
        UsersEventsRoles(user=user, event=event, role=role)
    db.session.commit()

    return event
def get_room(db, user=None, **kwargs):
    room = MicrolocationSubFactory(**kwargs)
    if user:
        role, _ = get_or_create(Role, name='owner', title_name='Owner')
        UsersEventsRoles(user=user, event=room.event, role=role)
    db.session.commit()

    return room
def get_stream(db, user=None, **kwargs):
    stream = VideoStreamFactoryBase(**kwargs)
    room = MicrolocationSubVideoStreamFactory(video_stream=stream)
    if user:
        role, _ = get_or_create(Role, name='owner', title_name='Owner')
        UsersEventsRoles(user=user, event=room.event, role=role)
    db.session.commit()

    return stream
def get_minimal_attendee(db, user=None, owner=False, event_status='published'):
    attendee = AttendeeOrderTicketSubFactory(
        order__user=user if not owner else None, event__state=event_status)
    if owner:
        role, _ = get_or_create(Role, name='owner', title_name='Owner')
        UsersEventsRoles(user=user, event=attendee.event, role=role)
    db.session.commit()

    return attendee
Esempio n. 12
0
 def after_update_object(self, role_invite, data, view_kwargs):
     user = User.query.filter_by(email=role_invite.email).first()
     if 'status' in data and data['status'] == 'accepted':
         role = Role.query.filter_by(name=role_invite.role_name).first()
         event = Event.query.filter_by(id=role_invite.event_id).first()
         uer = UsersEventsRoles.query.filter_by(user=user).filter_by(
             event=event).filter_by(role=role).first()
         if not uer:
             uer = UsersEventsRoles(user, event, role)
             save_to_db(uer, 'Role Invite accepted')
Esempio n. 13
0
def test_notify_event_role(db):
    invite = RoleInviteSubFactory()
    role, _ = get_or_create(Role, name='owner', title_name='Owner')
    UsersEventsRoles(user=UserFactory(), event=invite.event, role=role)
    user = UserFactory()
    db.session.commit()
    notify_event_role_invitation(invite, user, invite.event.owner)

    notification = Notification.query.first()
    assert notification.user == user
    assert notification.content.type == NotificationType.EVENT_ROLE
    assert notification.content.target == invite
    assert notification.content.actors[0].actor == invite.event.owner
Esempio n. 14
0
def get_session(db, user, event_owner=False, **kwargs):
    new_user = UserFactory(is_admin=False, is_verified=False)

    if event_owner:
        owner = user
        creator = new_user
    else:
        owner = new_user
        creator = user
    session = SessionSubFactory(creator_id=creator.id, **kwargs)
    role, _ = get_or_create(Role, name='owner', title_name='Owner')
    UsersEventsRoles(user=owner, event=session.event, role=role)
    db.session.commit()

    return session
Esempio n. 15
0
def get_event(db, user=None):
    event = EventFactoryBasic(state='published')
    if user:
        role, _ = get_or_create(Role, name='owner', title_name='Owner')
        UsersEventsRoles(user=user, event=event, role=role)
    CustomForms(
        event=event,
        form='speaker',
        field_identifier='email',
        type='text',
        is_included=True,
        is_required=True,
    )
    db.session.commit()

    return event
Esempio n. 16
0
def test_send_monthly_invoice(db):
    """Method to test monthly invoices"""

    TicketFeesFactory(service_fee=10.23, maximum_fee=11, country='global')
    test_order = OrderSubFactory(
        status='completed',
        event__state='published',
        completed_at=monthdelta(this_month_date(), -1),
        amount=100,
    )
    role, _ = get_or_create(Role, name='owner', title_name='Owner')
    UsersEventsRoles(user=UserFactory(), event=test_order.event, role=role)
    AttendeeSubFactory(event=test_order.event, order=test_order)
    db.session.commit()

    send_monthly_event_invoice()
    event_invoice = test_order.event.invoices[0]
    assert event_invoice.amount == 10.23
 def after_create_object(self, event, data, view_kwargs):
     """
     after create method to save roles for users
     :param event:
     :param data:
     :param view_kwargs:
     :return:
     """
     role = Role.query.filter_by(name=ORGANIZER).first()
     user = User.query.filter_by(id=view_kwargs['user_id']).first()
     uer = UsersEventsRoles(user, event, role)
     save_to_db(uer, 'Event Saved')
     if data.get('original_image_url'):
         uploaded_images = create_save_image_sizes(
             data['original_image_url'], 'event', event.id)
         self.session.query(Event).filter_by(
             id=event.id).update(uploaded_images)
         self.session.commit()
Esempio n. 18
0
def test_create_order_override_amount_organizer(client, db, user, jwt):
    event = EventFactoryBasic()
    tickets = _create_tickets([10, 20], event=event, quantity=2)
    role, _ = get_or_create(Role, name='owner', title_name='Owner')
    UsersEventsRoles(user=user, event=event, role=role)
    db.session.commit()

    response = client.post(
        '/v1/orders/create-order',
        content_type='application/json',
        headers=jwt,
        data=json.dumps({
            'amount': 0,
            'tickets': _create_ticket_dict(tickets, [1, 2])
        }),
    )

    assert response.status_code == 200
    order_dict = json.loads(response.data)
    order = Order.query.get(order_dict['data']['id'])
    assert order_dict['data']['attributes']['amount'] == 0
    assert order.amount == 0
Esempio n. 19
0
def get_owner(event, user):
    role, _ = get_or_create(Role, name='owner', title_name='Owner')
    UsersEventsRoles(user=user, event=event, role=role)
    return user
def test_email_sanitization(db, client, user, jwt):
    event = EventFactoryBasic()
    role_, _ = get_or_create(Role, name='owner', title_name='Owner')
    UsersEventsRoles(user=user, event=event, role=role_)
    role, _ = get_or_create(Role, name='organizer', title_name='Organizer')
    db.session.commit()

    data = json.dumps({
        'data': {
            'type': 'role-invite',
            "attributes": {
                "email": "test example.org ",
                "role_name": "organizer"
            },
            "relationships": {
                "event": {
                    "data": {
                        "id": str(event.id),
                        "type": "event"
                    }
                },
                "role": {
                    "data": {
                        "id": str(role.id),
                        "type": "role"
                    }
                },
            },
        }
    })

    response = client.post(
        '/v1/role-invites',
        content_type='application/vnd.api+json',
        headers=jwt,
        data=data,
    )

    assert (json.loads(
        response.data)['errors'][0]['detail'] == 'Not a valid email address.')
    assert response.status_code == 422

    data = json.dumps({
        'data': {
            'type': 'role-invite',
            "attributes": {
                "email": "  [email protected] ",
                "role_name": "organizer"
            },
            "relationships": {
                "event": {
                    "data": {
                        "id": str(event.id),
                        "type": "event"
                    }
                },
                "role": {
                    "data": {
                        "id": str(role.id),
                        "type": "role"
                    }
                },
            },
        }
    })

    response = client.post(
        '/v1/role-invites',
        content_type='application/vnd.api+json',
        headers=jwt,
        data=data,
    )

    assert json.loads(
        response.data)['data']['attributes']['email'] == '*****@*****.**'
    assert response.status_code == 201

    ri = RoleInviteSubFactory(event=event,
                              role=role,
                              email='  [email protected]  ')
    db.session.commit()
    response = client.get(
        f'/v1/role-invites/{ri.id}',
        content_type='application/vnd.api+json',
        headers=jwt,
        data=data,
    )

    assert json.loads(
        response.data)['data']['attributes']['email'] == '*****@*****.**'
Esempio n. 21
0
def create_owner(db, event):
    role, _ = get_or_create(Role, name='owner', title_name='Owner')
    UsersEventsRoles(user=UserFactory(), event=event, role=role)
    db.session.commit()
Esempio n. 22
0
def import_event_json(task_handle, zip_path, creator_id):
    """
    Imports and creates event from json zip
    """
    global CUR_ID, UPLOAD_QUEUE
    UPLOAD_QUEUE = []
    update_state(task_handle, 'Started')

    with app.app_context():
        path = app.config['BASE_DIR'] + '/static/uploads/import_event'
    # delete existing files
    if os.path.isdir(path):
        shutil.rmtree(path, ignore_errors=True)
    # extract files from zip
    with zipfile.ZipFile(zip_path, "r") as z:
        z.extractall(path)
    # create event
    try:
        update_state(task_handle, 'Importing event core')
        data = json.loads(open(path + '/event', 'r').read())
        _, data = _trim_id(data)
        srv = ('event', Event)
        data = _delete_fields(srv, data)
        new_event = Event(**data)
        save_to_db(new_event)
        role = Role.query.filter_by(name=OWNER).first()
        user = User.query.filter_by(id=creator_id).first()
        uer = UsersEventsRoles(user_id=user.id, event_id=new_event.id, role_id=role.id)
        save_to_db(uer, 'Event Saved')
        write_file(
            path + '/social_links',
            json.dumps(data.get('social_links', [])).encode('utf-8')
        )  # save social_links
        _upload_media_queue(srv, new_event)
    except Exception as e:
        raise make_error('event', er=e)
    # create other services
    try:
        service_ids = {}
        for item in IMPORT_SERIES:
            item[1].is_importing = True
            data = open(path + '/%s' % item[0], 'r').read()
            dic = json.loads(data)
            changed_ids = create_service_from_json(
                task_handle, dic, item, new_event.id, service_ids)
            service_ids[item[0]] = changed_ids.copy()
            CUR_ID = None
            item[1].is_importing = False
    except IOError:
        db.session.delete(new_event)
        db.session.commit()
        raise NotFoundError('File %s missing in event zip' % item[0])
    except ValueError:
        db.session.delete(new_event)
        db.session.commit()
        raise make_error(item[0], er=ServerError(source='Zip Upload',
                                                 detail='Invalid json'))
    except Exception:
        print(traceback.format_exc())
        db.session.delete(new_event)
        db.session.commit()
        raise make_error(item[0], id_=CUR_ID)
    # run uploads
    _upload_media(task_handle, new_event.id, path)
    # return
    return new_event