def delete(self, request): user_id = get_logged_in_user_id(request) if user_id: review_object = PartnerReview.objects.get(id=request.data['id']) if (user_id == review_object.submitted_by_account_id) or user_id == -1: review_object.status = 'Deleted' review_object.save() invalidate_cloudfront_caches() serializer = PartnerReviewSerializer(review_object) return Response(serializer.data) else: return Response(status=403, data="SSO cookie not set")
def patch(self, request): review_object = PartnerReview.objects.get(id=request.data['id']) serializer = PartnerReviewSerializer( review_object, data=request.data, partial=True) # set partial=True to update a data partially if serializer.is_valid(): serializer.save() # set review status to Edited so it will reenter the review queue review_object.status = 'Edited' review_object.save() invalidate_cloudfront_caches() return JsonResponse(status=201, data=serializer.data) return JsonResponse(status=400, data="wrong parameters")
def save(self, *args, **kwargs): # update instance dates if self.resolution: self.resolution_date = timezone.now() if self.status == "Reviewed": self.reviewed_date = timezone.now() if self.status == "Completed" and self.resolution != "Will Not Fix": self.corrected_date = timezone.now() # book updated field is being used front-end to show google the content is being maintained Book.objects.filter(pk=self.book.pk).update(updated=now()) # prefill resolution notes based on certain status and resolutions if self.resolution == "Duplicate" and not self.resolution_notes: self.resolution_notes = "This is a duplicate of report <a href='https://openstax.org/errata/" + str( self.duplicate_id.id) + "'>" + str( self.duplicate_id.id) + "</a>." if self.resolution == "Not An Error" and not self.resolution_notes: self.resolution_notes = "Our reviewers determined this was not an error." if self.resolution == "Will Not Fix" and not self.resolution_notes: self.resolution_notes = "Our reviewers determined the textbook meets scope, sequence, and accuracy requirements as is. No change will be made." if self.resolution == "Major Book Revision" and not self.resolution_notes: self.resolution_notes = "Our reviewers determined this would require a significant book revision. While we cannot make this change at this time, we will consider it for future editions of this book." if (self.status == "Reviewed" or self.status == "Completed" ) and self.resolution == "Approved" and not self.resolution_notes: self.resolution_notes = "Our reviewers accepted this change." if self.status == "Completed" and self.resolution == "Sent to Customer Support" and not self.resolution_notes: self.resolution_notes = "Thank you for this feedback. Your report has been escalated to our Support team. A member of the Support team will contact you with further details." if self.resolution == 'Technical Error' and not self.resolution_notes: self.resolution_notes = 'This a technical error and the proper departments have been notified so that it can be fixed. Thank you for your submission.' if self.resolution == 'More Information Requested' and not self.resolution_notes: self.resolution_notes = 'Thank you for the feedback. Unfortunately, our reviewers were unable to locate this error. Please submit a new report with additional information, such as a link to the relevant content, or a screenshot.' if self.resolution == 'Partner Product' and not self.resolution_notes: self.resolution_notes = 'This issue is occurring on a platform that is not managed by OpenStax. We will make our best efforts to get this resolved; however, we suggest reporting this issue within the platform you are using.' #auto filling a couple of fields if it is clear that it is an assessment errata based on the text that tutor fills into the additional_location_information field if self.additional_location_information and self.resource == 'OpenStax Tutor' and ( '@' in self.additional_location_information.split()[0]): self.is_assessment_errata = 'Yes' self.assessment_id = self.additional_location_information.split( '@', )[0] # set to archived if user is shadow banned if (is_user_shadow_blocked(self.submitted_by_account_id)): self.archived = True # invalidate cloudfront cache so FE updates (remove when errata is no longer in CMS) invalidate_cloudfront_caches() super(Errata, self).save(*args, **kwargs)
def post(self, request): try: try: review_object = PartnerReview.objects.get( partner=request.data['partner'], submitted_by_account_id=request. data['submitted_by_account_id']) except MultipleObjectsReturned: # just in case they somehow were able to create more than 1 review_object = PartnerReview.objects.filter( partner=request.data['partner'], submitted_by_account_id=request. data['submitted_by_account_id']).first() serializer = PartnerReviewSerializer(review_object) return Response(serializer.data) except PartnerReview.DoesNotExist: serializer = PartnerReviewSerializer(data=request.data) if serializer.is_valid(): serializer.save() invalidate_cloudfront_caches() return JsonResponse(status=201, data=serializer.data) return JsonResponse(status=400, data="wrong parameters")
def handle(self, *args, **options): with Salesforce() as sf: # To update the existing reviews with Partner responses and approved reviews. command = "Select Id, Status__c, Approved_Customer_Review__c, Pending_Customer_Review__c, Partner_Response__c, Partner_Response_Date__c, Partner__c, Contact__c, Score__c, OS_Accounts_ID__c FROM Partner_Review__c WHERE Status__c = 'Approved' OR Status__c = 'Responded'" response = sf.query_all(command) sf_reviews = response['records'] for record in sf_reviews: try: review = PartnerReview.objects.get(review_salesforce_id=record['Id']) if review.status != 'Edited': review.review = record['Approved_Customer_Review__c'] review.partner_response = record['Partner_Response__c'] review.partner_response_date = record['Partner_Response_Date__c'] review.status = 'Approved' review.save() except PartnerReview.DoesNotExist: print('Review does not exist for SF ID: {}'.format(record['Id'])) # Update rejected reviews command = "Select Id, Status__c, Approved_Customer_Review__c, Pending_Customer_Review__c, Partner_Response__c, Partner_Response_Date__c, Partner__c, Contact__c, Score__c, OS_Accounts_ID__c FROM Partner_Review__c WHERE Status__c = 'Rejected'" response = sf.query_all(command) sf_reviews = response['records'] for record in sf_reviews: try: review = PartnerReview.objects.get(review_salesforce_id=record['Id']) review.status = 'Rejected' review.save() except PartnerReview.DoesNotExist: print('Review does not exist for SF ID: {}'.format(record['Id'])) # If a review does not have a Salesforce ID, it must be new. We'll upload those to SF and assign a SF ID. new_reviews = PartnerReview.objects.filter(review_salesforce_id__isnull=True) for review in new_reviews: data = { 'Status__c': 'New', 'Pending_Customer_Review__c': review.review, 'Partner__c': review.partner.salesforce_id, 'OS_Accounts_ID__c': review.submitted_by_account_id, 'Score__c': review.rating, } try: response = sf.Partner_Review__c.create(data) review.review_salesforce_id = response['id'] review.save() except SalesforceGeneralError: print('Failed to create review in Salesforce - are you sure the partner exists?') # If a review is in the Edited state, it needs to be reuploaded to SF and set to 'New' update_reviews = PartnerReview.objects.filter(status='Edited') for review in update_reviews: data = { 'Status__c': 'New', 'Pending_Customer_Review__c': review.review, 'OS_Accounts_ID__c': review.submitted_by_account_id, 'Score__c': review.rating, } try: response = sf.Partner_Review__c.update(data=data, record_id=review.review_salesforce_id) review.status = 'Awaiting Approval' review.save() except SalesforceGeneralError: print('Failed to update review in Salesforce') # Finally, if a review was deleted by a user, let's delete it from Salesforce. reviews_to_delete = PartnerReview.objects.filter(status='Deleted') for review in reviews_to_delete: if review.review_salesforce_id: sf.Partner_Review__c.delete(review.review_salesforce_id) review.delete() invalidate_cloudfront_caches() response = self.style.SUCCESS("Successfully updated partner reviews") self.stdout.write(response)