def test_my_session_unauthorized_access(self): with app.test_request_context(): event = ObjectMother.get_event() user = ObjectMother.get_user() save_to_db(user, "User saved") save_to_db(event, "Event saved") speaker = Speaker(name="name", email="*****@*****.**", organisation="FOSSASIA", event_id=event.id, user=user, country="India") save_to_db(speaker, "Speaker saved") session = Session(title='test', long_abstract='dsad', start_time=datetime(2003, 8, 4, 12, 30, 45), end_time=datetime(2003, 8, 4, 12, 30, 45), event_id=event.id, speakers=[speaker], state='pending') save_to_db(session, "Session saved") rv = self.app.get(url_for('my_sessions.display_session_view', session_id=session.id), follow_redirects=True) self.assertEqual(rv.status_code, 404)
def before_post(self, args, kwargs, data=None): """ method to add user_id to view_kwargs before post :param args: :param kwargs: :param data: :return: """ data['user'] = current_user.id require_relationship(['event', 'user'], data) if not has_access('is_coorganizer', event_id=data['event']): event = db.session.query(Event).filter_by(id=data['event']).one() if event.state == "draft": raise ObjectNotFound( {'parameter': 'event_id'}, "Event: {} not found".format(data['event']), ) if (get_count( db.session.query(Event).filter_by( id=int(data['event']), is_sessions_speakers_enabled=False)) > 0): raise ForbiddenError({'pointer': ''}, "Speakers are disabled for this Event") if (not data.get('is_email_overridden') and get_count( db.session.query(Speaker).filter_by(event_id=int( data['event']), email=data['email'], deleted_at=None)) > 0): raise ForbiddenError({'pointer': ''}, 'Speaker with this Email ID already exists') if data.get('is_email_overridden') and not has_access( 'is_organizer', event_id=data['event']): raise ForbiddenError( {'pointer': 'data/attributes/is_email_overridden'}, 'Organizer access required to override email', ) if (data.get('is_email_overridden') and has_access('is_organizer', event_id=data['event']) and not data.get('email')): data['email'] = current_user.email if 'sessions' in data: session_ids = data['sessions'] for session_id in session_ids: if not has_access('is_session_self_submitted', session_id=session_id): raise ObjectNotFound( {'parameter': 'session_id'}, f"Session: {session_id} not found", ) data[ 'complex_field_values'] = validate_custom_form_constraints_request( 'speaker', self.schema, Speaker(event_id=data['event']), data)
def create_services(event_id, serial_no=''): """Creates services and associates them with `event_id`. Service names have an optional `serial_no` that can be used to make them unique. """ test_micro = 'TestMicrolocation{}_{}'.format(serial_no, event_id) test_track = 'TestTrack{}_{}'.format(serial_no, event_id) test_session = 'TestSession{}_{}'.format(serial_no, event_id) test_speaker = 'TestSpeaker{}_{}'.format(serial_no, event_id) test_sponsor = 'TestSponsor{}_{}'.format(serial_no, event_id) test_sponsor_type = 'TestSponsorType{}_{}'.format(serial_no, event_id) test_session_type = 'TestSessionType{}_{}'.format(serial_no, event_id) test_social_link = 'TestSocialLink{}_{}'.format(serial_no, event_id) microlocation = Microlocation(name=test_micro, event_id=event_id) track = Track( name=test_track, description='descp', event_id=event_id, color='#caf034' ) session_type = SessionType( name=test_session_type, length=30, event_id=event_id ) session = Session(title=test_session, long_abstract='descp', start_time=datetime(2014, 8, 4, 12, 30, 45), end_time=datetime(2014, 8, 4, 13, 00, 00), event_id=event_id, session_type=session_type) speaker = Speaker(name=test_speaker, email='*****@*****.**', organisation='org', country='japan', event_id=event_id) sponsor = Sponsor(name=test_sponsor, sponsor_type=test_sponsor_type, event_id=event_id, level='level') social_link = SocialLink( name=test_social_link, link='http://fb.com', event_id=event_id ) save_to_db(social_link, 'SocialLink saved') save_to_db(session_type, 'SessionType saved') save_to_db(microlocation, 'Microlocation saved') save_to_db(track, 'Track saved') save_to_db(session, 'Session saved') save_to_db(speaker, 'Speaker saved') save_to_db(sponsor, 'Sponsor saved')
def add_speaker(self, payloads): response = ResponseBuilder() self.speaker = Speaker() self.speaker.user_id = payloads['user_id'] self.speaker.job = payloads['job'] self.speaker.summary = payloads['summary'] self.speaker.information = payloads['information'] self.speaker.type = payloads['type'] db.session.add(self.speaker) try: db.session.commit() data = self.speaker.as_dict() return response.set_data(data).build() except SQLAlchemyError as e: data = e.orig.args return response.set_data(data).set_error(True).build()
def scrape_session(self, session_page): self.browser.get(session_page) speakers = self.speaker_dao.find_all() speakers_by_name = { speaker['speaker_name']: speaker for speaker in speakers } sessions = self.session_dao.find_all() sessions_by_session_id = { session['session_id']: session for session in sessions } self.wait_by_class_name("session") sessions = self.browser.find_elements_by_class_name("session") for session_element in sessions: session = Session() session.from_web_element(session_element) if session.session_id not in sessions_by_session_id: _id = self.session_dao.create(session) session._id = _id sessions_by_session_id[session.session_id] = session speaker_elements = self.browser.find_elements_by_xpath( "//*[@data-modal='user_profile']") for speaker_element in speaker_elements: speaker = Speaker() speaker.from_web_element(speaker_element) if speaker.speaker_name not in speakers_by_name: _id = self.speaker_dao.create(speaker) speaker._id = _id speakers_by_name[speaker.speaker_name] = speaker return len(sessions)
def test_my_session_detail(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event saved") speaker = Speaker(name="name", email="*****@*****.**", organisation="FOSSASIA", event_id=event.id, user=self.super_admin, country="India") save_to_db(speaker, "Speaker saved") session = Session(title='test session', long_abstract='dsad', start_time=datetime(2003, 8, 4, 12, 30, 45), end_time=datetime(2003, 8, 4, 12, 30, 45), event_id=event.id, speakers=[speaker], state='pending') save_to_db(session, "Session saved") rv = self.app.get(url_for('my_sessions.display_session_view', session_id=session.id), follow_redirects=True) self.assertTrue("test session" in rv.data, msg=rv.data)
def setUp(self): self.app = Setup.create_app() with app.test_request_context(): event = Event(name=UNICODE_STRING, start_time=datetime(2013, 8, 4, 12, 30, 45), end_time=datetime(2016, 9, 4, 12, 30, 45)) event.owner = 1 microlocation = Microlocation(name=UNICODE_STRING) session = Session(title=UNICODE_STRING, long_abstract='descp', start_time=datetime(2014, 8, 4, 12, 30, 45), end_time=datetime(2015, 9, 4, 12, 30, 45)) speaker = Speaker(name=UNICODE_STRING, email='*****@*****.**', organisation='org', country='japan') sponsor = Sponsor(name=UNICODE_STRING) save_to_db(event, "Event saved") save_to_db(microlocation, 'Microlocation saved') save_to_db(session, 'Session saved') save_to_db(speaker, 'Speaker saved') save_to_db(sponsor, 'Sponsor saved')
def save_speaker(request, event_id=None, speaker=None, user=None, no_name=False): if not speaker and not event_id: raise Exception('event_id or speaker is required') from app.helpers.data import save_to_db, record_activity if not speaker: if no_name: speaker = Speaker(event_id=event_id, user=user, name='', email=trim_get_form(request.form, 'email', None)) else: speaker = Speaker(event_id=event_id, user=user, name=trim_get_form(request.form, 'name', None), email=trim_get_form(request.form, 'email', None)) save_to_db(speaker) speaker.email = trim_get_form(request.form, 'email', None) if trim_get_form(request.form, 'name', None): speaker.name = trim_get_form(request.form, 'name', speaker.name) if not speaker.user: if user: speaker.user = user else: speaker.user = DataGetter.get_or_create_user_by_email( speaker.email, { 'firstname': speaker.name, 'lastname': '' }) if not event_id: event_id = speaker.event_id image_sizes = speaker_image_sizes() if not speaker.photo: photo = trim_get_form(request.form, 'photo', None) if photo and photo.strip() != '': if speaker.photo != photo: file_path = get_path_of_temp_url(photo) speaker.photo = save_untouched_photo(photo, event_id, speaker.id) speaker.small = save_resized_photo(file_path, event_id, speaker.id, 'small', image_sizes) speaker.thumbnail = save_resized_photo(file_path, event_id, speaker.id, 'thumbnail', image_sizes) speaker.icon = save_resized_photo(file_path, event_id, speaker.id, 'icon', image_sizes) else: speaker.photo = '' speaker.small = '' speaker.thumbnail = '' speaker.icon = '' speaker.short_biography = trim_get_form(request.form, 'short_biography', speaker.short_biography) speaker.long_biography = trim_get_form(request.form, 'long_biography', speaker.long_biography) speaker.mobile = trim_get_form(request.form, 'mobile', speaker.mobile) speaker.website = trim_get_form(request.form, 'website', speaker.website) speaker.twitter = trim_get_form(request.form, 'twitter', speaker.twitter) speaker.facebook = trim_get_form(request.form, 'facebook', speaker.facebook) speaker.github = trim_get_form(request.form, 'github', speaker.github) speaker.linkedin = trim_get_form(request.form, 'linkedin', speaker.linkedin) speaker.organisation = trim_get_form(request.form, 'organisation', speaker.organisation) speaker.featured = True if request.form.get( 'featured', speaker.featured) == 'true' else False speaker.position = trim_get_form(request.form, 'position', speaker.position) speaker.country = trim_get_form(request.form, 'country', speaker.country) speaker.city = trim_get_form(request.form, 'city', speaker.city) speaker.gender = trim_get_form(request.form, 'gender', speaker.gender) if trim_get_form(request.form, 'heard_from', None) == "Other": speaker.heard_from = trim_get_form(request.form, 'other_text', speaker.other_text) else: speaker.heard_from = trim_get_form(request.form, 'heard_from', speaker.heard_from) speaker.sponsorship_required = trim_get_form(request.form, 'sponsorship_required', speaker.sponsorship_required) speaker.speaking_experience = trim_get_form(request.form, 'speaking_experience', speaker.speaking_experience) speakers_modified.send(app._get_current_object(), event_id=event_id) save_to_db(speaker, "Speaker has been updated") record_activity('update_speaker', speaker=speaker, event_id=event_id) return speaker
def import_data(file_path, creator_id, task_handle): update_status(task_handle, 'Parsing iCal file') file = open(file_path, 'rb') calendar = Calendar.from_ical(file.read()) update_status(task_handle, 'Processing event') event = Event() if 'X-WR-CALNAME' in calendar: event.name = get_valid_event_name(calendar.decoded('X-WR-CALNAME')) if not event.name and 'X-WR-CALDESC' in calendar: event.name = get_valid_event_name(calendar.decoded('X-WR-CALDESC')) for session in calendar.walk('vevent'): if not event.name: event.name = get_valid_event_name(session.decoded('UID')) start_time = session.decoded('dtstart') end_time = session.decoded('dtend') if not event.start_time or start_time < event.start_time: event.start_time = start_time if not event.end_time or end_time > event.end_time: event.end_time = end_time if not event.name: event.name = 'Un-named Event' # Event name set if 'X-WR-TIMEZONE' in calendar: event.timezone = calendar.decoded('X-WR-TIMEZONE') event.has_session_speakers = True event.state = 'Published' event.privacy = 'public' db.session.add(event) update_status(task_handle, 'Adding sessions') for session_block in calendar.walk('vevent'): track_id = None if 'CATEGORIES' in session_block: categories = session_block['CATEGORIES'] string_to_hash = categories if not hasattr(categories, '__iter__') else categories[0] seed = int('100'.join(list(str(ord(character)) for character in string_to_hash))) random.seed(seed) color = "#%06x" % random.randint(0, 0xFFFFFF) track, _ = get_or_create(Track, event_id=event.id, name=string_to_hash, color=color) track_id = track.id microlocation, _ = get_or_create(Microlocation, event_id=event.id, name=session_block.decoded('location')) session = Session() session.track_id = track_id session.microlocation_id = microlocation.id session.title = session_block.decoded('summary') session.short_abstract = session_block.decoded('description') session.start_time = session_block.decoded('dtstart') session.end_time = session_block.decoded('dtend') session.signup_url = session_block.decoded('url') session.event_id = event.id session.state = 'accepted' session.speakers = [] save_to_db(session, 'Session Updated') attendees = [] if 'attendee' in session_block: attendees_dirty = session_block['attendee'] if hasattr(attendees_dirty, '__iter__'): for attendee in attendees_dirty: attendees.append((attendee.params['CN'], attendee)) else: attendees.append((attendees_dirty.params['CN'], attendees_dirty)) for attendee in attendees: speaker = Speaker(name=attendee[0], event_id=event.id, email=attendee[1].replace('MAILTO:', ''), country='Earth', organisation='') db.session.add(speaker) session.speakers.append(speaker) db.session.commit() update_status(task_handle, 'Added session "' + session.title + '"') update_status(task_handle, 'Saving data') save_to_db(event) update_status(task_handle, 'Finalizing') own_event(event=event, user_id=creator_id) return event
def import_from_pentabarf(file_path=None, string=None, creator=None, task_handle=None): if file_path: with open(file_path, 'r') as xml_file: string = xml_file.read().replace('\n', '') if not creator: creator = current_user try: update_status(task_handle, 'Parsing XML file') conference_object = PentabarfParser.parse(string) update_status(task_handle, 'Processing event') event = Event() event.start_time = conference_object.start event.end_time = conference_object.end event.has_session_speakers = True event.creator = creator event.name = conference_object.title event.location_name = conference_object.venue + ', ' + conference_object.city event.searchable_location_name = conference_object.city event.state = 'Published' event.privacy = 'public' db.session.add(event) update_status(task_handle, 'Adding sessions') index = 1 for day_object in conference_object.day_objects: for room_object in day_object.room_objects: microlocation, _ = get_or_create(Microlocation, event_id=event.id, name=room_object.name) for event_object in room_object.event_objects: session_type_id = None if event_object.type: session_type, _ = get_or_create( SessionType, event_id=event.id, name=event_object.type, length=30) session_type_id = session_type.id track_id = None if event_object.track: string_to_hash = event_object.track seed = int('100'.join( list( str(ord(character)) for character in string_to_hash))) random.seed(seed) color = "#%06x" % random.randint(0, 0xFFFFFF) track, _ = get_or_create(Track, event_id=event.id, name=event_object.track, color=color) track_id = track.id session = Session() session.track_id = track_id session.microlocation_id = microlocation.id session.session_type_id = session_type_id session.title = event_object.title session.short_abstract = event_object.abstract session.long_abstract = event_object.description session.start_time = event_object.date + string_to_timedelta( event_object.start) session.end_time = session.start_time + string_to_timedelta( event_object.duration) session.slides = event_object.slides_url session.video = event_object.video_url session.audio = event_object.audio_url session.signup_url = event_object.conf_url session.event_id = event.id session.state = 'accepted' db.session.add(session) update_status(task_handle, 'Adding session "' + session.title + '"') index += 1 for person_object in event_object.person_objects: name_mix = person_object.name + ' ' + conference_object.title email = ''.join( x for x in name_mix.title() if not x.isspace()) + '@example.com' speaker = Speaker(name=person_object.name, event_id=event.id, email=email, country='Earth', organisation=person_object.name) db.session.add(speaker) update_status(task_handle, 'Saving data') save_to_db(event) update_status(task_handle, 'Finalizing') except Exception as e: from app.api.helpers.import_helpers import make_error raise make_error('event', er=e) return event
def get_speaker(): return Speaker(name="name", email="*****@*****.**", organisation="FOSSASIA", country="India")
def run(): """ Create 4 Users seeds """ # create admin admin = User() admin.first_name = 'Admin' admin.last_name = 'Herman' admin.email = '*****@*****.**' admin.username = '******' admin.hash_password('supersecret') admin.role_id = 1 db.session.add(admin) # create ganesh ganesh = User() ganesh.first_name = 'Ganesh' ganesh.last_name = 'Cauda' ganesh.email = '*****@*****.**' ganesh.username = '******' ganesh.hash_password('supersecret') ganesh.role_id = 7 ganesh.points = 0 db.session.add(ganesh) # create erdi erdi = User() erdi.first_name = 'Erdi' erdi.last_name = 'yansah' erdi.email = '*****@*****.**' erdi.username = '******' erdi.hash_password('supersecret') erdi.role_id = 3 db.session.add(erdi) # create mgufrone guffy = User() guffy.first_name = 'Mochamad' guffy.last_name = 'Gufrone' guffy.email = '*****@*****.**' guffy.username = '******' guffy.hash_password('supersecret') guffy.role_id = 4 db.session.add(guffy) db.session.commit() # create booth for erdi erdi_booth = Booth() erdi_booth.user_id = 3 erdi_booth.points = 10000 erdi_booth.stage = None erdi_booth.summary = 'Promoting Mytrhil.js to Indonesia' db.session.add(erdi_booth) # create speaker for guffy guffy_speaker = Speaker() guffy_speaker.user_id = 4 guffy_speaker.information = '-' guffy_speaker.summary = 'code 24.1 hours' guffy_speaker.job = 'COO & Senior software developer at Refactory' db.session.add(guffy_speaker) db.session.commit()
def import_data(file_path, creator_id, task_handle): with open(file_path, 'r') as xml_file: string = xml_file.read().replace('\n', '') update_status(task_handle, 'Parsing XML file') conference_object = PentabarfParser.parse(string) update_status(task_handle, 'Processing event') event = Event() event.start_time = conference_object.start event.end_time = conference_object.end event.has_session_speakers = True event.name = conference_object.title event.location_name = conference_object.venue # + ', ' + conference_object.city event.searchable_location_name = conference_object.city event.state = 'Published' event.privacy = 'public' db.session.add(event) event_time_updated = False update_status(task_handle, 'Adding sessions') for day_object in conference_object.day_objects: for room_object in day_object.room_objects: microlocation, _ = get_or_create(Microlocation, event_id=event.id, name=room_object.name) for event_object in room_object.event_objects: session_type_id = None if event_object.type: session_type, _ = get_or_create(SessionType, event_id=event.id, name=event_object.type, length=str(30)) # TODO: hardcoded here session_type_id = session_type.id track_id = None if event_object.track: string_to_hash = event_object.track seed = int('100'.join(list(str(ord(character)) for character in string_to_hash))) random.seed(seed) color = "#%06x" % random.randint(0, 0xFFFFFF) track, _ = get_or_create(Track, event_id=event.id, name=event_object.track, color=color) track_id = track.id session = Session() session.track_id = track_id session.microlocation_id = microlocation.id session.session_type_id = session_type_id session.title = event_object.title session.short_abstract = event_object.abstract session.long_abstract = event_object.description session.level = getattr(event_object, 'level', None) # https://github.com/niranjan94/python-pentabarf-xml/issues/3 session.start_time = event_object.date + string_to_timedelta(event_object.start) session.end_time = session.start_time + string_to_timedelta(event_object.duration) session.slides = event_object.slides_url session.video = event_object.video_url session.audio = event_object.audio_url session.signup_url = event_object.conf_url session.event_id = event.id session.state = 'accepted' session.speakers = [] save_to_db(session, 'Session Updated') if not event_time_updated: event.start_time = None event.end_time = None event_time_updated = True if not event.start_time or session.start_time < event.start_time: event.start_time = session.start_time if not event.end_time or session.end_time > event.end_time: event.end_time = session.end_time for person_object in event_object.person_objects: name_mix = person_object.name + ' ' + conference_object.title email = ''.join(x for x in name_mix.title() if not x.isspace()) + '@example.com' speaker = Speaker(name=person_object.name, event_id=event.id, email=email, country='Earth', organisation='') db.session.add(speaker) session.speakers.append(speaker) db.session.commit() update_status(task_handle, 'Added session "' + session.title + '"') update_status(task_handle, 'Saving data') save_to_db(event) update_status(task_handle, 'Finalizing') own_event(event=event, user_id=creator_id) return event
def _to_json(self, object_record: dict) -> Speaker: speaker_model = Speaker() speaker_model.from_json(object_record) return speaker_model