Ejemplo n.º 1
0
def approve_event(event_id):
    sessionObj = request.session
    creator_id = sessionObj.user_id
    eventObj = db.session.query(Event).filter(
        Event.event_id == event_id).first()

    roleObj = db.session.query(Role).filter(
        Role.user_id == creator_id,
        Role.organization_id == eventObj.organization_id).first()
    print("DEBUG...")
    print(eventObj)
    print(roleObj)
    if roleObj is None or not roleObj:
        return {
            'message': "You do not have any role in this organization",
            'success': False
        }

    if roleObj.role != Roles.CHAIRMAN and roleObj.role != Roles.ADMIN:
        return {
            'message':
            'You need to be an admin/chairperson in this organization to approve events',
            'success': False
        }
    eventObj.phase = EventPhase.APPROVED
    db.session.commit()
    event_schema = EventSchema()

    result = {'message': event_schema.dump(eventObj), 'success': True}

    return result
Ejemplo n.º 2
0
def get_all_published_event():
    events = db.session.query(Event).filter(
        Event.phase == EventPhase.APPROVED).all()
    if events:
        events_schema = EventSchema(many=True)
        #events = events.schema.dump(self)
        result = events_schema.dump(events)
        return jsonify(result=result, success=True)
    else:
        return {'message': 'There is no published event.', 'success': False}
Ejemplo n.º 3
0
def get_all_published_event():
    """
    Show all published event
    ---
    tags:
      - event
    response:
        200:
            description: OK
            content:
                application/json:
                    schema:
                        type: object
                        properties:
                            success:
                                type: boolean
                            result:
                                type: array
                                items:
                                    type: object
                                    properties:
                                        categories:
                                            type: string
                                        contact_id:
                                            type: string
                                        creator_id:
                                            type: string
                                        end_date:
                                            type: string
                                        event_id:
                                            type: string
                                        event_name:
                                            type: string
                                        info:
                                            type: string
                                        organization_id:
                                            type: string
                                        perks:
                                            type: string
                                        phase:
                                            type: integer
                                        start_date:
                                            type: string
                                        theme:
                                            type: string
    """
    events = db.session.query(Event).filter(
        Event.phase == EventPhase.APPROVED).all()
    if events:
        events_schema = EventSchema(many=True)
        # events = events.schema.dump(self)
        result = events_schema.dump(events)
        return jsonify(result=result, success=True)
    else:
        return {'message': 'There is no published event.', 'success': False}
Ejemplo n.º 4
0
def get_all_published_events(org_id):
    """ Return a specific organization by its ID """
    # Verify the organize exists.
    organization = Organization.query.filter_by(organization_id=org_id).first()
    if organization:
        events = db.session.query(Event).filter(
            (Event.organization_id == organization.organization_id),
            Event.phase == EventPhase.APPROVED).all()
        events_schema = EventSchema(many=True)
        result = events_schema.dump(events)
        #result = EventSchema.dump(events, many=True)
        return jsonify(result=result, success=True)
    else:
        return jsonify(success=False,
                       message="The organization does not exists.")
Ejemplo n.º 5
0
def get_all_unpublished_event(org_id):
    events = db.session.query(Event).filter(
        or_(Event.phase == EventPhase.INITIALIZED,
            Event.phase == EventPhase.ARCHIVED),
        Event.organization_id == org_id).all()
    user = request.user
    if user.roles.filter(Role.role == Roles.MEMBER):
        return {
            'message': 'You are not allowed to see unpublished event',
            'success': False
        }

    if events:
        events_schema = EventSchema(many=True)
        result = events_schema.dump(events)
        return jsonify(result=result, success=True)
    else:
        return {'message': 'There is no unpublished event.', 'success': False}
Ejemplo n.º 6
0
def cancel_event(event_id):
    sessionObj = request.session
    creator_id = sessionObj.user_id
    eventObj = db.session.query(Event).filter(
        Event.event_id == event_id).first()
    if eventObj is None or not eventObj:
        return {'message': "This event does not exist !!! ", 'success': False}

    roleObj = db.session.query(Role).filter(
        Role.user_id == creator_id,
        Role.organization_id == eventObj.organization_id).first()
    print("DEBUG...")
    print(eventObj)
    print(roleObj)
    # if the event exist, check a status of the person
    if roleObj is None or not roleObj:
        return {
            'message': "You do not have any role in this organization",
            'success': False
        }

    if roleObj.role != Roles.CHAIRMAN:
        return {
            'message':
            'You need to be an CHAIRMAN in this organization to cancel events',
            'success': False
        }
    # This is admin or chairman
    eventObj.phase = EventPhase.ARCHIVED
    db.session.commit()
    event_schema = EventSchema()

    result = {
        'message': event_schema.dump(eventObj) + " have been canceled",
        'success': True
    }

    return result
Ejemplo n.º 7
0
def create_event(org_id):
    sessionObj = request.session
    creator_id = sessionObj.user_id

    roleObj = db.session.query(Role).filter(
        Role.user_id == creator_id, Role.organization_id == org_id).first()
    if roleObj is None or not roleObj:
        return {
            'message': "You do not have any role in this organization",
            'success': False
        }

    if roleObj.role != Roles.ADMIN:
        return {
            'message':
            'You need to be an ADMIN in this organization to create events',
            'success': False
        }

    userObj = sessionObj.user
    orgObj = roleObj.organization
    contact = orgObj.contact

    input_data = request.json

    event_data = {
        "creator": userObj,
        "organization": orgObj,
        "contact": contact,
        "event_name": input_data['event_name'],
        "start_date": datetime.fromisoformat(input_data['start_date']),
        "end_date": datetime.fromisoformat(input_data['end_date']),
        "theme": input_data['theme'],
        "perks": input_data['perks'],
        "categories": input_data['categories'],
        "info": input_data['info'],
        "phase": EventPhase.INITIALIZED
    }
    # print("DEBUG....")
    # print(sessionObj)
    is_event_name_exist = Event.query.filter_by(
        event_name=event_data['event_name']).first()
    if is_event_name_exist:
        return jsonify(
            message='This name is already taken. Please choose another name.',
            success=False)

    new_event = Event(**event_data)
    db.session.add(new_event)

    chairmanObj = db.session.query(Role).filter(
        Role.role == Roles.CHAIRMAN, Role.organization_id == org_id).first()

    notification_data = {
        "sender": userObj,
        "receiver": chairmanObj.user,
        "info": "EVENT created"
    }

    notify_chairman = Notification(**notification_data)
    db.session.add(notify_chairman)
    db.session.commit()
    event_schema = EventSchema()

    result = {'message': event_schema.dump(new_event), 'success': True}
    return result
Ejemplo n.º 8
0
def edit_event(event_id, **kwargs):
    '''
    Edit an existing event
    ---
    tags:
      - event
    parameters:
      - in: body
        name: body
        required: true
        schema:
          required:
            - event_name
            - start_date
            - end_date
            - theme
            - perks
            - categories
            - info
          properties:
            event_name:
              type: string
            start_date:
              type: string
              description: An ISO 8601 formatted datetime string
            end_date:
              type: string
              description: An ISO 8601 formatted datetime string
            theme:
              type: string
            perks:
              type: string
            categories:
              type: string
            info:
              type: string
    responses:
        200:
            description: OK
            content:
                application/json:
                    schema:
                        type: object
                        properties:
                            success:
                                type: boolean
                            message:
                                type: string
                            session:
                                type: object
                                properties:
                                    token:
                                        type: string
                                    expires:
                                        type: string
    '''

    user = request.user
    event = db.session.query(Event).filter(Event.event_id == event_id).first()
    role = user.roles.filter(
        Role.organization == event.organization,
        or_(Role.role == Roles.ADMIN, Role.role == Roles.CHAIRMAN)).first()

    if role == None:
        return {
            'success': False,
            'message': 'You don\'t have permission to do that!'
        }, 403

    # Perform post-processing/sanitization of fields
    kwargs['start_date'] = datetime.fromisoformat(kwargs['start_date'])
    kwargs['end_date'] = datetime.fromisoformat(kwargs['end_date'])

    # Only unpack certain fields to prevent other fields from being edited
    permitted_keys = [
        'event_name', 'start_date', 'end_date', 'theme', 'perks', 'categories',
        'info'
    ]
    for key, value in kwargs.items():
        if key in permitted_keys: setattr(event, key, value)

    db.session.commit()
    return {'success': True, 'message': '', 'event': EventSchema().dump(event)}
Ejemplo n.º 9
0
def get_all_published_events(org_id):
    """
    Show all published events of an events
    ---
        tags:
          - event
        response:
            200:
                description: OK
                content:
                    application/json:
                        schema:
                            type: object
                            properties:
                                success:
                                    type: boolean
                                result:
                                    type: array
                                    items:
                                        type: object
                                        properties:
                                            categories:
                                                type: string
                                            contact_id:
                                                type: string
                                            creator_id:
                                                type: string
                                            end_date:
                                                type: string
                                            event_id:
                                                type: string
                                            event_name:
                                                type: string
                                            info:
                                                type: string
                                            organization_id:
                                                type: string
                                            perks:
                                                type: string
                                            phase:
                                                type: integer
                                            start_date:
                                                type: string
                                            theme:
                                                type: string
    """
    # Verify the organize exists.
    organization = Organization.query.filter_by(organization_id=org_id).first()
    if organization is None:
        return jsonify(success=False,
                       message="The organization does not exists.")
    else:
        events = db.session.query(Event).filter(
            (Event.organization_id == organization.organization_id),
            Event.phase == EventPhase.APPROVED).all()
        if events is None:
            return jsonify(
                success=False,
                message="The organization does not have any events.")
        else:
            events_schema = EventSchema(many=True)
            result = events_schema.dump(events)
            return jsonify(result=result, success=True)
Ejemplo n.º 10
0
def get_all_unpublished_event(org_id):
    """
        Show all unpublished events by organization (only chairman and admin allow to see the list)
        ---
        tags:
          - event
        response:
            200:
                description: OK
                content:
                    application/json:
                        schema:
                            type: object
                            properties:
                                success:
                                    type: boolean
                                result:
                                    type: array
                                    items:
                                        type: object
                                        properties:
                                            categories:
                                                type: string
                                            contact_id:
                                                type: string
                                            creator_id:
                                                type: string
                                            end_date:
                                                type: string
                                            event_id:
                                                type: string
                                            event_name:
                                                type: string
                                            info:
                                                type: string
                                            organization_id:
                                                type: string
                                            perks:
                                                type: string
                                            phase:
                                                type: integer
                                            start_date:
                                                type: string
                                            theme:
                                                type: string
        """
    events = db.session.query(Event).filter(
        or_(Event.phase == EventPhase.INITIALIZED,
            Event.phase == EventPhase.ARCHIVED),
        Event.organization_id == org_id).all()

    user = request.user
    member = db.session.query(Role).filter(
        Role.user_id == user.user_id).first()
    if member.role == Roles.MEMBER:
        return {
            'message': 'You are not allowed to see unpublished event',
            'success': False
        }

    if events:
        events_schema = EventSchema(many=True)
        result = events_schema.dump(events)
        return jsonify(result=result, success=True)
    else:
        return {'message': 'There is no unpublished event.', 'success': False}