def get(self, odoo_contact_id): """Return generated unique link for alumni to register. Link will be expired in 1 week. """ # check if such odoo user exists filter_list = [] filter_list.append(['id', '=', odoo_contact_id]) from app.controllers.odoo_controller import OdooController try: contacts_number = OdooController.count_number_of_odoo_contacts_by_filter_list(filter_list) except OdooIsDeadError as err: abort(503, err, error_id='odoo_connection_error') if contacts_number == 0: return { "error_id": "odoo_contact_not_found_error", "message": "Odoo contact not found." }, 404 # encrypt odoo user id token = encode_token(odoo_contact_id) # create/update record in alumni invite status from app.controllers.alumni_invite_status_controller import AlumniInviteStatusController put_data = { "odoo_contact_id": odoo_contact_id, "invite_status": "invited" } response = AlumniInviteStatusController.update_invite_status_record(put_data) return { "token": token, }, 200
def post(self, form_id): """Confirm update form - send data to odoo. """ post_data = request.get_json() from app.controllers.update_form_controller import UpdateFormController update_data = UpdateFormController.get_update_form_by_id(form_id)[0] print("UPDATE DATA") print(update_data) from app.controllers.alumni_controller import AlumniController odoo_contact_id = AlumniController.get_odoo_contact_id_by_alumni_id(update_data.get("alumni_id")) from app.controllers.odoo_controller import OdooController try: contact = OdooController.update_odoo_contact(odoo_contact_id, update_data) except OdooIsDeadError as err: abort(503, err, error_id='odoo_connection_error') else: # TODO: raise error in update_odoo_contact if contact is None: return {"message": "Error in updating odoo contact."}, 400 else: # else if success - change update form status and operator who confirmed from app.controllers.update_form_controller import UpdateFormController put_data = { 'form_status': 'approved', 'operator_id': post_data.get('operator_id') } UpdateFormController.change_update_form_status(form_id, put_data) return {"message": "Odoo contact successfully updated."}, 200
def get(self): """Get all countries from odoo. """ from app.controllers.odoo_controller import OdooController try: response = OdooController.get_odoo_countries() except OdooIsDeadError as err: abort(503, err, error_id='odoo_connection_error') return response
def post(self): """ Login to alumni service. """ post_data = request.get_json() email = post_data.get('email') password = post_data.get('password') from app.controllers.alumni_controller import AlumniController alumni = AlumniController.get_alumni_user_by_email(email) if alumni is None: return { "error_id": "alumni_login_wrong_email_error", "message": "Unauthorized: wrong email." }, 401 if not alumni.check_password(password): return { "error_id": "alumni_login_wrong_password_error", "message": "Unauthorized: wrong password." }, 401 # if user exists get data from odoo contact and create access token for the user filter_list = [] filter_list.append(['id', '=', int(alumni.odoo_contact_id)]) from app.controllers.odoo_controller import OdooController try: contact = OdooController.get_odoo_contacts_by_filter_list( filter_list, 0, 0) except OdooIsDeadError as err: abort(503, err, error_id='odoo_connection_error') if not contact: return { "error_id": "odoo_contact_not_found_error", "message": "Odoo contact not found." }, 404 # return alumni data contact[0].update({ "alumni_id": alumni.alumni_id, "alumni_email": alumni.email, "alumni_uuid": alumni.alumni_uuid, "user_confirmed": alumni.user_confirmed, "allow_show_contacts": alumni.allow_show_contacts, }) return { "alumni": contact, "access_token": create_access_token(identity=alumni.email), "refresh_token": create_refresh_token(identity=alumni.email) }, 200
def post(self): """Register new alumni user. """ post_data = request.get_json() # decode token and check if expired token = post_data.get('odoo_contact_token') odoo_contact_id, expiration_date = decode_token(token) if datetime.now() > expiration_date: return { "error_id": "alumni_register_link_expired_error", "message": "Unauthorized: Registration link is expired." }, 401 # check if such odoo user exists filter_list = [] filter_list.append(['id', '=', odoo_contact_id]) from app.controllers.odoo_controller import OdooController try: contacts_number = OdooController.count_number_of_odoo_contacts_by_filter_list( filter_list) except OdooIsDeadError as err: abort(503, err, error_id='odoo_connection_error') if contacts_number == 0: return { "error_id": "odoo_contact_not_found_error", "message": "Odoo contact not found." }, 404 # create alumni user from app.controllers.alumni_controller import AlumniController post_data.update({'odoo_contact_id': odoo_contact_id}) response = AlumniController.create_alumni_user(post_data) if response[1] == 201: # delete record in alumni invite status from app.controllers.alumni_invite_status_controller import AlumniInviteStatusController AlumniInviteStatusController.delete_invite_status_record( odoo_contact_id) # send email for confirmation receiver_email = response[0]['email'] alumni_uuid = response[0]['alumni_uuid'] send_confirmation_email(receiver_email, alumni_uuid) return response
def post(self): """Confirm new created alumni. """ post_data = request.get_json() alumni_uuid = post_data.get("alumni_uuid") # check alumni with uuid exists from app.controllers.alumni_controller import AlumniController alumni = AlumniController.get_alumni_by_uuid(alumni_uuid) if alumni is None: return { "error_id": "alumni_not_found_error", "message": "Alumni not found." }, 404 else: # update alumni status to confirmed from app.controllers.alumni_controller import AlumniController put_data = {"alumni_id": alumni.alumni_id, "user_confirmed": True} AlumniController.update_alumni_user(put_data) # get alumni odoo contact filter_list = [] filter_list.append(['id', '=', int(alumni.odoo_contact_id)]) from app.controllers.odoo_controller import OdooController try: contacts = OdooController.get_odoo_contacts_by_filter_list( filter_list, 0, 0) except OdooIsDeadError as err: abort(503, err, error_id='odoo_connection_error') contact = contacts[0] # return alumni data contact.update({ "alumni_id": alumni.alumni_id, "alumni_email": alumni.email, "alumni_uuid": alumni.alumni_uuid, "user_confirmed": alumni.user_confirmed, "allow_show_contacts": alumni.allow_show_contacts, }) return { "alumni": contact, "access_token": create_access_token(identity=alumni.email), "refresh_token": create_refresh_token(identity=alumni.email) }, 200
def get(self, odoo_contact_id): """Get odoo contact by id """ filter_list = [] filter_list.append(['id', '=', int(odoo_contact_id)]) from app.controllers.odoo_controller import OdooController try: contacts = OdooController.get_odoo_contacts_by_filter_list( filter_list, 0, 0) except OdooIsDeadError as err: abort(503, err, error_id='odoo_connection_error') if not len(contacts): return { "error_id": "odoo_contact_not_found_error", "message": "No odoo contact with such an id exists." }, 404 contact = contacts[0] # get alumni user from app.controllers.alumni_controller import AlumniController alumni = AlumniController.get_alumni_by_odoo_id(str(contact.get('id'))) if alumni is not None: contact.update({ "alumni_id": alumni.alumni_id, "alumni_email": alumni.email, "alumni_uuid": alumni.alumni_uuid, "user_confirmed": alumni.user_confirmed, "allow_show_contacts": alumni.allow_show_contacts, }) return contact, 200
def get(self, odoo_contact_id): """Get Bachelor and Master groupmates for alumni with given alumni id. """ query_params = request.args offset = query_params.get('offset', 0) limit = query_params.get('limit', 0) # get odoo contact by id filter_list = [] filter_list.append(['id', '=', int(odoo_contact_id)]) from app.controllers.odoo_controller import OdooController try: contacts = OdooController.get_odoo_contact_with_groupmates_fields( filter_list) except OdooIsDeadError as err: abort(503, err, error_id='odoo_connection_error') # TODO: throw contact not found error if not len(contacts): return { "error_id": "odoo_contact_not_found_error", "message": "No odoo contact with such an id exists." }, 404 contact = contacts[0] print(f"CONTACT {contact}") # append filters for groupmates bachelor_speciality = contact.get('bachelor_speciality') bachelor_year_in = contact.get('bachelor_year_in') master_speciality = contact.get('master_speciality') master_year_in = contact.get('master_year_in') if bachelor_speciality and bachelor_year_in and master_speciality and master_year_in: groupmates_filter_list = [ '&', ('id', '!=', odoo_contact_id), '|', '&', ('bachelor_speciality', '=', bachelor_speciality), ('bachelor_year_in', '=', bachelor_year_in), '&', ('master_speciality', '=', master_speciality), ('master_year_in', '=', master_year_in) ] elif bachelor_speciality and bachelor_year_in: groupmates_filter_list = [ '&', ('id', '!=', odoo_contact_id), '&', ('bachelor_speciality', '=', bachelor_speciality), ('bachelor_year_in', '=', bachelor_year_in) ] elif master_speciality and master_year_in: groupmates_filter_list = [ '&', ('id', '!=', odoo_contact_id), '&', ('master_speciality', '=', master_speciality), ('master_year_in', '=', master_year_in) ] else: return { "error_id": "no_required_groupmates_fields_error", "message": "No required fields to get groupmates: should be both speciality and entry year given." }, 400 # get all groupmates (both bachelor and masters) try: contacts = OdooController.get_odoo_contacts_by_filter_list( groupmates_filter_list, offset, limit) except OdooIsDeadError as err: abort(503, err, error_id='odoo_connection_error') # get all registered alumni id from app.controllers.alumni_controller import AlumniController registered_alumni_odoo_ids_allow_show_contacts = AlumniController.get_alumni_odoo_id_allow_show_contacts_dict( ) # map contacts with statuses (registered/unregistered) and allow_show_contacts field for x in contacts: x.update({ "alumni_status": "registered" if str( x['id']) in registered_alumni_odoo_ids_allow_show_contacts else "unregistered", "allow_show_contacts": registered_alumni_odoo_ids_allow_show_contacts.get( str(x['id']), False) }) return contacts, 200
def get(self): """Return all registered alumni (for operator side). """ query_params = request.args offset = query_params.get('offset', 0) limit = query_params.get('limit', 0) bachelor_faculty = query_params.get('bachelor_faculty') bachelor_speciality = query_params.get('bachelor_speciality') bachelor_year_in = query_params.get('bachelor_year_in') bachelor_year_out = query_params.get('bachelor_year_out') master_faculty = query_params.get('master_faculty') master_speciality = query_params.get('master_speciality') master_year_in = query_params.get('master_year_in') master_year_out = query_params.get('master_year_out') user_confirmed = query_params.get('user_confirmed') from app.controllers.alumni_controller import AlumniController registered_alumni_odoo_ids = AlumniController.get_all_registered_alumni_odoo_ids( ) filter_list = [] filter_list.append(['id', 'in', registered_alumni_odoo_ids]) filter_list.append(['bachelor_faculty', '=', bachelor_faculty ]) if bachelor_faculty else None filter_list.append(['bachelor_speciality', '=', bachelor_speciality ]) if bachelor_speciality else None filter_list.append(['bachelor_year_in', '=', bachelor_year_in ]) if bachelor_year_in else None filter_list.append(['bachelor_year_out', '=', bachelor_year_out ]) if bachelor_year_out else None filter_list.append(['master_faculty', '=', master_faculty ]) if master_faculty else None filter_list.append(['master_speciality', '=', master_speciality ]) if master_speciality else None filter_list.append(['master_year_in', '=', master_year_in ]) if master_year_in else None filter_list.append(['master_year_out', '=', master_year_out ]) if master_year_out else None from app.controllers.odoo_controller import OdooController try: contacts = OdooController.get_odoo_contacts_by_filter_list( filter_list, offset, limit) except OdooIsDeadError as err: abort(503, err, error_id='odoo_connection_error') # map contact for x in contacts: alumni = AlumniController.get_alumni_by_odoo_id(str(x['id'])) x.update({ "alumni_id": alumni.alumni_id, "alumni_email": alumni.email, "alumni_uuid": alumni.alumni_uuid, "user_confirmed": alumni.user_confirmed, "allow_show_contacts": alumni.allow_show_contacts, }) # filter contact by user confirmed status of exists if user_confirmed is not None: user_confirmed = True if user_confirmed == 'true' else False contacts = [ x for x in contacts if x['user_confirmed'] == user_confirmed ] # TODO: fix user confirmed query param is str return contacts, 200
def get(self): """Get all alumni (for alumni side). """ query_params = request.args offset = query_params.get('offset', 0) limit = query_params.get('limit', 0) bachelor_faculty = query_params.get('bachelor_faculty') bachelor_speciality = query_params.get('bachelor_speciality') bachelor_year_in = query_params.get('bachelor_year_in') bachelor_year_out = query_params.get('bachelor_year_out') master_faculty = query_params.get('master_faculty') master_speciality = query_params.get('master_speciality') master_year_in = query_params.get('master_year_in') master_year_out = query_params.get('master_year_out') filter_list = [] filter_list.append(['is_alumni', '=', True]) filter_list.append(['bachelor_faculty', '=', bachelor_faculty ]) if bachelor_faculty else None filter_list.append(['bachelor_speciality', '=', bachelor_speciality ]) if bachelor_speciality else None filter_list.append(['bachelor_year_in', '=', bachelor_year_in ]) if bachelor_year_in else None filter_list.append(['bachelor_year_out', '=', bachelor_year_out ]) if bachelor_year_out else None filter_list.append(['master_faculty', '=', master_faculty ]) if master_faculty else None filter_list.append(['master_speciality', '=', master_speciality ]) if master_speciality else None filter_list.append(['master_year_in', '=', master_year_in ]) if master_year_in else None filter_list.append(['master_year_out', '=', master_year_out ]) if master_year_out else None # get all alumni from odoo from app.controllers.odoo_controller import OdooController try: contacts = OdooController.get_odoo_contacts_by_filter_list( filter_list, offset, limit) except OdooIsDeadError as err: abort(503, err, error_id='odoo_connection_error') # get all registered alumni id from app.controllers.alumni_controller import AlumniController registered_alumni_odoo_ids_allow_show_contacts = AlumniController.get_alumni_odoo_id_allow_show_contacts_dict( ) # map contacts with statuses (registered/unregistered) and allow_show_contacts field for x in contacts: x.update({ "alumni_status": "registered" if str( x['id']) in registered_alumni_odoo_ids_allow_show_contacts else "unregistered", "allow_show_contacts": registered_alumni_odoo_ids_allow_show_contacts.get( str(x['id']), False) }) return contacts, 200
def get(self): """Return all unregistered alumni (for operator side). """ query_params = request.args offset = query_params.get('offset', 0) limit = query_params.get('limit', 0) bachelor_faculty = query_params.get('bachelor_faculty') bachelor_speciality = query_params.get('bachelor_speciality') bachelor_year_in = query_params.get('bachelor_year_in') bachelor_year_out = query_params.get('bachelor_year_out') master_faculty = query_params.get('master_faculty') master_speciality = query_params.get('master_speciality') master_year_in = query_params.get('master_year_in') master_year_out = query_params.get('master_year_out') invite_status = query_params.get('invite_status') filter_list = [] filter_list.append(['is_company', '=', False]) filter_list.append(['is_alumni', '=', True]) # get all odoo alumni ids from app.controllers.odoo_controller import OdooController try: all_alumni_ids = OdooController.get_odoo_contacts_ids_by_filter_list( filter_list) except OdooIsDeadError as err: abort(503, err, error_id='odoo_connection_error') # get all registered alumni ids from app.controllers.alumni_controller import AlumniController registered_alumni_odoo_ids = AlumniController.get_all_registered_alumni_odoo_ids( ) # not registered and not invited alumni ids together not_registered_alumni_odoo_ids = [ x for x in all_alumni_ids if x not in registered_alumni_odoo_ids ] filter_list.append(['id', 'in', not_registered_alumni_odoo_ids]) filter_list.append(['bachelor_faculty', '=', bachelor_faculty ]) if bachelor_faculty else None filter_list.append(['bachelor_speciality', '=', bachelor_speciality ]) if bachelor_speciality else None filter_list.append(['bachelor_year_in', '=', bachelor_year_in ]) if bachelor_year_in else None filter_list.append(['bachelor_year_out', '=', bachelor_year_out ]) if bachelor_year_out else None filter_list.append(['master_faculty', '=', master_faculty ]) if master_faculty else None filter_list.append(['master_speciality', '=', master_speciality ]) if master_speciality else None filter_list.append(['master_year_in', '=', master_year_in ]) if master_year_in else None filter_list.append(['master_year_out', '=', master_year_out ]) if master_year_out else None # get contacts from odoo try: contacts = OdooController.get_odoo_contacts_by_filter_list( filter_list, offset, limit) except OdooIsDeadError as err: abort(503, err, error_id='odoo_connection_error') # get all NOT registered alumni ids with statuses (invited, no response, rejected etc.) from app.controllers.alumni_invite_status_controller import AlumniInviteStatusController not_registerd_alumni_records = AlumniInviteStatusController.get_id_status_records_dict( ) # map odoo contacts with statuses for x in contacts: status = not_registerd_alumni_records.get(str(x['id'])) x.update({"alumni_status": status if status else "not invited"}) # filter by status query param if exists if invite_status is not None: contacts = [ x for x in contacts if x['alumni_status'] == invite_status ] return contacts, 200