def get_messages(): """Supplier dashboard (Messages) (role=supplier) --- tags: - dashboard definitions: SellerDashboardMessageItems: type: object properties: messages: type: array items: $ref: '#/definitions/SellerDashboardMessageItem' SellerDashboardMessageItem: type: object properties: message: type: string severity: type: string responses: 200: description: Seller dashboard data for the 'Notifications' tab schema: $ref: '#/definitions/SellerDashboardMessageItems' """ messages = supplier_business.get_supplier_messages( current_user.supplier_code, False) items = messages.warnings + messages.errors if messages: return jsonify(messages={'items': items}), 200 else: return jsonify(messages={'items': []}), 200
def get_messages(): messages = supplier_business.get_supplier_messages( current_user.supplier_code, False) items = messages.warnings + messages.errors if messages: return jsonify(messages={'items': items}), 200 else: return jsonify(messages={'items': []}), 200
def get_notification_count(user): notification_count = None if user.role == 'supplier': errors_warnings = supplier_business.get_supplier_messages( user.supplier_code, False) notification_count = len(errors_warnings.errors + errors_warnings.warnings) return notification_count
def supplier_dashboard(): supplier = suppliers.first(code=current_user.supplier_code) messages = supplier_business.get_supplier_messages( current_user.supplier_code, False) items = messages.warnings + messages.errors return jsonify(supplier={ 'name': supplier.name, 'code': supplier.code, 'is_recruiter_only': True if supplier.data.get('recruiter', '') == 'yes' else False }, messages={'items': items}), 200
def get_supplier_messages(code): """Get supplier messages (role=supplier) --- tags: - messages security: - basicAuth: [] parameters: - name: code in: path type: int required: true definitions: Message: type: object properties: severity: type: string message: type: string step: type: string Messages: properties: warnings: type: array items: $ref: '#/definitions/Message' errors: type: array items: $ref: '#/definitions/Message' responses: 200: description: supplier messages schema: $ref: '#/definitions/Messages' """ skip_application_check = request.args.get('skip_application_check', True) messages = supplier_business.get_supplier_messages(code, skip_application_check) if messages: return jsonify(warnings=messages.warnings, errors=messages.errors), 200 else: return jsonify(warnings=[], errors=[]), 200
def get_user_by_id(user_id): user = (db.session.query( User.active, User.application_id, User.created_at, User.email_address, User.failed_login_count, User.id, User.failed_login_count, User.logged_in_at, User.name, User.password_changed_at, User.phone_number, User.role, User.supplier_code, User.terms_accepted_at, User.updated_at, Supplier.name.label('supplier_name')).outerjoin(Supplier).filter( User.id == user_id).one_or_none()) result = user._asdict() login_attempt_limit = current_app.config['DM_FAILED_LOGIN_LIMIT'] result['locked'] = user.failed_login_count >= login_attempt_limit notification_count = 0 teams = [] if user.role == 'supplier': messages = supplier_business.get_supplier_messages( user.supplier_code, False) notification_count = len(messages.errors + messages.warnings) elif user.role == 'buyer': teams = team_business.get_user_teams(user.id) result.update({'teams': teams}) result.update({ 'supplier': { 'name': user.supplier_name, 'supplierCode': user.supplier_code, 'notificationCount': notification_count } }) result.update({'application': {'id': user.application_id}}) legacy = { 'emailAddress': user.email_address, 'phoneNumber': user.phone_number, 'createdAt': user.created_at, 'updatedAt': user.updated_at, 'passwordChangedAt': user.password_changed_at, 'loggedInAt': user.logged_in_at if user.logged_in_at else None, 'termsAcceptedAt': user.terms_accepted_at, 'failedLoginCount': user.failed_login_count } result.update(legacy) return jsonify(users=result)
def auth_user(): json_payload = get_json_from_request() json_has_required_keys(json_payload, ["authUsers"]) json_payload = json_payload["authUsers"] validate_user_auth_json_or_400(json_payload) email_address = json_payload.get('email_address', None) if email_address is None: # will remove camel case email address with future api email_address = json_payload.get('emailAddress', None) user = User.query.options( joinedload('supplier'), noload('supplier.*'), joinedload('application'), noload('application.*'), noload('*') ).filter( User.email_address == email_address.lower() ).first() if user is None or (user.supplier and user.supplier.status == 'deleted'): return jsonify(authorization=False), 404 elif encryption.authenticate_user(json_payload['password'], user) and user.active: user.logged_in_at = datetime.utcnow() user.failed_login_count = 0 db.session.add(user) db.session.commit() validation_result = None if user.role == 'supplier': messages = supplier_business.get_supplier_messages(user.supplier_code, False) validation_result = ( messages._asdict() if messages else None ) return jsonify(users=user.serialize(), validation_result=validation_result), 200 else: user.failed_login_count += 1 db.session.add(user) db.session.commit() return jsonify(authorization=False), 403
def supplier_dashboard(): """Seller dashboard (role=supplier) --- tags: - dashboard definitions: SellerDashboard: type: object properties: supplier: type: object properties: code: type: string name: type: string messages: type: object properties: items: $ref: '#/definitions/SellerDashboardMessageItem' responses: 200: description: Supplier dashboard info schema: $ref: '#/definitions/SellerDashboard' """ supplier = suppliers.first(code=current_user.supplier_code) messages = supplier_business.get_supplier_messages( current_user.supplier_code, False) items = messages.warnings + messages.errors return jsonify(supplier={ 'name': supplier.name, 'code': supplier.code, 'is_recruiter_only': True if supplier.data.get('recruiter', '') == 'yes' else False }, messages={'items': items}), 200
def get_brief_responses(brief_id): """All brief responses (role=supplier,buyer) --- tags: - brief security: - basicAuth: [] parameters: - name: brief_id in: path type: number required: true definitions: BriefResponses: properties: briefResponses: type: array items: id: BriefResponse responses: 200: description: A list of brief responses schema: id: BriefResponses 404: description: brief_id not found """ brief = briefs.get(brief_id) if not brief: not_found("Invalid brief id '{}'".format(brief_id)) if current_user.role == 'buyer': brief_user_ids = [user.id for user in brief.users] if current_user.id not in brief_user_ids: return forbidden("Unauthorised to view brief or brief does not exist") supplier_code = getattr(current_user, 'supplier_code', None) if current_user.role == 'supplier': validation_result = supplier_business.get_supplier_messages(supplier_code, True) if len(validation_result.errors) > 0: abort(validation_result.errors) # strip data from seller view if 'sellers' in brief.data: brief.data['sellers'] = {} if brief.responses_zip_filesize: brief.responses_zip_filesize = None if 'industryBriefing' in brief.data: brief.data['industryBriefing'] = '' if 'attachments' in brief.data: brief.data['attachments'] = [] if 'backgroundInformation' in brief.data: brief.data['backgroundInformation'] = '' if 'outcome' in brief.data: brief.data['outcome'] = '' if 'endUsers' in brief.data: brief.data['endUsers'] = '' if 'workAlreadyDone' in brief.data: brief.data['workAlreadyDone'] = '' if 'timeframeConstraints' in brief.data: brief.data['timeframeConstraints'] = '' if 'contactNumber' in brief.data: brief.data['contactNumber'] = '' if current_user.role == 'buyer' and brief.status != 'closed': brief_responses = [] else: brief_responses = brief_responses_service.get_brief_responses(brief_id, supplier_code) return jsonify(brief=brief.serialize(with_users=False, with_author=False), briefResponses=brief_responses)