def update(request, space_id, project_id, data): project = db_utils.find(space_id, 'Project', {'_id': project_id})[0] data['projectId'] = project_id snapshot = [] last_stage = stage_service.get_last_stage(space_id, project_id) if data['type'] == 'Epic' and ('color' not in data or data['color'] == None): data['color'] = 'color_' + str( (nextval(space_id, 'epicColor', project_id) % 10) + 1) if '_id' not in data: data['taskId'] = project['name'][:4].upper() + '-' + str( nextval(space_id, 'taskId', project_id)) data['order'] = nextval(space_id, 'taskOrder', project_id) else: snapshot = db_utils.find(space_id, domain, {'_id': data['_id']}) if data['stageId'] == last_stage['_id']: data['status'] = 'complete' updated_record = db_utils.upsert(space_id, domain, data, request.user_id) if '_id' in data and len(snapshot) == 1: log_service.add(space_id, domain, snapshot[0], updated_record, [ 'type', 'title', 'description', 'assignedTo', 'parentTaskId', 'priority', 'timeEstimate', 'storyPoints' ], request.user_id) return (200, {'data': updated_record})
def update_profile(space_id, data, user_id): user_list = db_utils.find(space_id, domain, { '_id': user_id, 'emailConfirmation': True }) if len(user_list) < 1: return (404, {'data': 'user does not exist'}) else: user = user_list[0] if 'firstName' in data: user['firstName'] = data['firstName'] if 'lastName' in data: user['lastName'] = data['lastName'] db_utils.upsert(space_id, domain, user) return (200, {'data': 'profile updated'})
def create(data): appspaceData = [] if 'appspaceId' in data: appspaceData = db_utils.find(database_name, domain, {'appspaceId': data['appspaceId']}) if len(appspaceData) == 1: return (404, {'data': 'appspace exists'}) else: data['appspaceId'] = str(sequence_service.nextval( 100, 'spaceId', 'na')) updated_record = db_utils.upsert(database_name, domain, { 'name': data['name'], 'appspaceId': data['appspaceId'] }) return (200, {'data': updated_record})
def add(request, space_id, project_id, team_id): if role_service.is_project_admin(space_id, request.user_id, project_id): existing_list = db_utils.find(space_id, domain, { 'projectId': project_id, 'teamId': team_id }) if len(existing_list) == 0: inserted_record = db_utils.upsert(space_id, domain, { 'projectId': project_id, 'teamId': team_id }, request.user_id) return (200, {'data': inserted_record}) else: return (200, {'data': existing_list[0]}) else: return (401, {'data': 'unauthorized'})
def find(request, space_id): # member_projects = find_member_projects(space_id, request.user_id) # admin_projects = find_admin_projects(space_id, request.user_id) all_projects = find_all_projects(space_id) projectid_list = [] # for item in member_projects: # if item['projectId'] not in projectid_list: # projectid_list.append(ObjectId(item['projectId'])) # for item in admin_projects: # if item['domainId'] not in projectid_list: # projectid_list.append(ObjectId(item['domainId'])) # projects = db_utils.find(space_id, domain, {'_id': {'$in': projectid_list}}) projects = db_utils.find(space_id, domain, {}) return 200, {'data': projects}
def delete(request, space_id, id): existing_record = db_utils.find(space_id, domain, {'_id': id}) if len(existing_record) > 0: authorized = False if existing_record[0]['type'] == 'ProjectAdministrator': authorized = is_project_admin(space_id, request.user_id, existing_record[0]['domainId']) elif existing_record[0]['type'] == 'TeamAdministrator': authorized = is_team_admin(space_id, request.user_id, existing_record[0]['domainId']) if authorized: result = db_utils.delete(space_id, domain, {'_id': id}, request.user_id) return (200, {'deleted_count': result.deleted_count}) else: return (401, {'data': 'unauthorized'}) else: return (404, {'data': 'no matching role found'})
def do_authorize_google(space_id, token): print(token) try: idinfo = id_token.verify_oauth2_token( token, requests.Request(), "81306451496-fg67eb502dvfb50c31huhkbn481bi29h.apps.googleusercontent.com" ) print(idinfo) if idinfo['iss'] not in [ 'accounts.google.com', 'https://accounts.google.com' ]: raise ValueError('Wrong issuer.') existing_user = db_utils.find(space_id, domain, {'email': idinfo['email']}) if len(existing_user) < 1: updated_user = db_utils.upsert( space_id, domain, { 'firstName': idinfo['given_name'], 'lastName': idinfo['family_name'], 'email': idinfo['email'], 'emailConfirmation': True, 'type': 'google' }) else: updated_user = db_utils.upsert( space_id, domain, { '_id': existing_user[0]['_id'], 'firstName': idinfo['given_name'], 'lastName': idinfo['family_name'], 'email': idinfo['email'], 'emailConfirmation': True, 'type': 'google' }) auth_key = create_session(space_id, updated_user) return (200, {'auth_key': auth_key}) # ID token is valid. Get the user's Google Account ID from the decoded token. # userid = idinfo['sub'] except ValueError: return (401, {'data': 'unauthorized'})
def change_password(space_id, data, user_id): user_list = db_utils.find(space_id, domain, { '_id': user_id, 'emailConfirmation': True }) if len(user_list) < 1: return (404, {'data': 'user does not exist'}) else: user = user_list[0] try: decoded_text = decrypt(user['cipher'], user['salt'], data['oldPassword'], user['iv']) except: return (401, {'data': 'unauthorized'}) if hash(decoded_text) == user['hash']: user['password'] = data['newPassword'] auth_user_data = get_user_with_auth_data(user) db_utils.upsert(space_id, domain, auth_user_data) return (200, {'data': 'password updated'}) else: return (401, {'data': 'unauthorized'})
def delete(request, space_id, id): tasks = db_utils.find(space_id, domain_task, {'stageId': id}) task_deleted_count = 0 task_attachment_deleted_count = 0 task_checklist_deleted_count = 0 task_comment_deleted_count = 0 for task in tasks: result = task_service.delete_by_id(space_id, task['_id'], request.user_id) task_attachment_deleted_count += result['attachments_deleted'] task_checklist_deleted_count += result['checklists_deleted'] task_comment_deleted_count += result['comments_deleted'] task_deleted_count += result['tasks_deleted'] stage_result = db_utils.delete(space_id, domain, {'_id': id}, request.user_id) return (200, { 'task_deleted_count': task_deleted_count, 'task_attachment_deleted_count': task_attachment_deleted_count, 'task_checklist_deleted_count': task_checklist_deleted_count, 'task_comment_deleted_count': task_comment_deleted_count, 'stages_deleted': stage_result.deleted_count })
def do_authorize_facebook(space_id, data): existing_user = db_utils.find(space_id, domain, {'email': data['email']}) if len(existing_user) < 1: updated_user = db_utils.upsert( space_id, domain, { 'firstName': data['firstName'], 'lastName': data['lastName'], 'email': data['email'], 'emailConfirmation': True, 'type': 'facebook' }) else: updated_user = db_utils.upsert( space_id, domain, { '_id': existing_user[0]['_id'], 'firstName': data['firstName'], 'lastName': data['lastName'], 'email': data['email'], 'emailConfirmation': True, 'type': 'facebook' }) auth_key = create_session(space_id, updated_user) return (200, {'auth_key': auth_key})
def find_all(request, tenant): data = db_utils.find(tenant, domain, {}) return (200, {'data': data})
def find_by_teams(space_id, team_list): return db_utils.find(space_id, domain, {'teamId': {'$in': team_list}})
def introspect(request): data = db_utils.find(database_name, domain, {}, project=['name', 'appspaceId']) return (200, {'data': data})
def find_template(template_name): results = db_utils.find(self_space, domain, {'name': template_name}) if len(results) > 0: return results[0] else: return None
def find_by_id(request, space_id, id): data = db_utils.find(space_id, domain, {'_id': id}) return 200, {'data': data}
def is_first_user(space_id): data = db_utils.find(space_id, domain, {}) if len(data) == 0: return True else: return False
def find_by_user_id(space_id, user_id): return db_utils.find(space_id, domain, {'_id': user_id})
def find_by_app_id(request, app_id): data = db_utils.find(database_name, domain, {'appId': app_id}) if len(data) == 1: return (200, {'data': data[0]}) else: return (404, {'data': 'not found'})
def find_admin_teams(space_id, user_id): return db_utils.find(space_id, domain, { 'userId': user_id, 'type': 'TeamAdministrator' })
def find_admin_projects(space_id, user_id): return db_utils.find(space_id, domain, { 'userId': user_id, 'type': 'ProjectAdministrator' })
def do_update_space(space_id, data): spaceData = db_utils.find(self_space_id, domain, {'name': space_id})[0] updated_data = db_utils.upsert(self_space_id, domain, data) return (200, {'data': updated_data})
def get_all_spaces(): return db_utils.find('recoso', 'space', {})
def find_all_domains(space_id): return db_utils.find(space_id, domain, {})
def find_all_projects(space_id): return db_utils.find(space_id, domain, {})
def find_all(request, space_id): data = db_utils.find(space_id, domain, {}) return (200, {'data': data})
def get_by_reference(space_id, project_reference): data = db_utils.find(space_id, domain, {"reference": project_reference}) if len(data) == 1: return data[0] else: return None
def find_by_project_id(request, space_id, project_id): data = db_utils.find(space_id, domain, {'project_id': project_id}) return 200, {'data': data}
def download_attachment(request, space_id, attachment_id): data = db_utils.find(space_id, domain, {'_id': attachment_id}) if len(data) == 1: return (200, base64.b64encode(data[0]['attachment'])) else: return (404, {'data': 'attachment not found'})
def find(request, space_id): domains = db_utils.find(space_id, domain, {}) return 200, {'data': domains}
def find_faq_by_category(request, space_id, category): data = db_utils.find(space_id, domain, {'category': category}) return (200, {'data': data})