예제 #1
0
파일: api.py 프로젝트: heccjj/openstax-cms
    def detail_view(self, request, pk):

        any_hidden = False

        response = super().detail_view(request, pk)
        page = Page.objects.get(pk=pk)

        # Implementing User Authentication
        auth_user = json.loads(get_user_data(request).content.decode())

        # Fetching User Information and Overwriting auth_user
        if "user" in auth_user:
            auth_user = get_user_info(auth_user["user"]["id"])

        # Overwriting the Response if ox credential does not
        # authorize faculty access.
        if "faculty_status" not in auth_user or auth_user[
                "faculty_status"] != "confirmed_faculty":
            if flag_state('hide_faculty_resources', bool=True):
                any_hidden = remove_locked_links_detail(response)

        # Implementing Caching
        response['Cache-Control'] = 'no-cache'

        # If we ended up revealing a link, then force the content to be loaded.
        if not any_hidden or request.GET.get('force-reload'):
            response['Last-Modified'] = timezone.now()

        return response
예제 #2
0
def edit(request):
    edit_errata = request.GET.get('errata', False)
    errata = False
    user = None

    if request.method == 'POST':
        form = ErrataModelForm(request.POST, request.FILES)

        if form.is_valid():
            errata = form.save()
            if request.POST.get('duplicate', False):
                duplicate(errata)
            else:
                return redirect('/apps/cms/api/errata/admin/dashboard/'
                                )  #TODO: change to URL resolver name

    else:
        if edit_errata:
            errata = Errata.objects.get(pk=edit_errata)
            user = get_user_info(errata.submitted_by_account_id)
            form = ErrataModelForm(instance=errata)
        else:
            form = ErrataModelForm()

    return render(request, 'errata/edit.html', {
        'errata': errata,
        'form': form,
        'user': user
    })
예제 #3
0
파일: api.py 프로젝트: heccjj/openstax-cms
    def listing_view(self, request):

        response = super().listing_view(request)

        # Implementing User Authentication
        auth_user = json.loads(get_user_data(request).content.decode())

        # Fetching User Information and Overwriting auth_user
        if "user" in auth_user:
            auth_user = get_user_info(auth_user["user"]["id"])

        # Overwriting the Response if ox credential does not
        # authorize faculty access.
        if "faculty_status" not in auth_user or auth_user[
                "faculty_status"] != "confirmed_faculty":
            if flag_state('hide_faculty_resources', bool=True):
                remove_locked_links_listing(response)

        return response
예제 #4
0
    def handle(self, *args, **options):
        print('Total Errata: {}'.format(Errata.objects.all().count()))
        updated_errata = 0
        no_user = 0

        for errata in Errata.objects.all():
            try:
                user = get_user_info(errata.submitted_by_account_id)
                if user:
                    errata.accounts_user_email = user['email']
                    errata.accounts_user_name = user['fullname']
                    errata.accounts_user_faculty_status = user[
                        'faculty_status']
                    errata.save()
                    updated_errata = updated_errata + 1
                else:
                    no_user = no_user + 1
            except Exception as e:
                print(e)
                break

        print('Updated Errata Count: {}'.format(updated_errata))
        print('No User Found Count: {}'.format(no_user))
예제 #5
0
def send_status_update_email(sender, instance, created, **kwargs):
        send_email = False
        override_to = False

        if created:
            if instance.created.month in (11, 12, 1, 2):
                email_text = EmailText.objects.get(email_case='Created in fall')
                subject = email_text.email_subject_text
                body = email_text.email_body_text
                send_email = True
            else:
                email_text = EmailText.objects.get(email_case='Created in fall')
                subject = email_text.email_subject_text
                body = email_text.email_body_text
                send_email = True
        elif instance.status == 'Reviewed' and (instance.resolution == 'Will Not Fix' or instance.resolution == 'Duplicate' or instance.resolution == 'Not An Error' or instance.resolution == 'Major Book Revision'):
            email_text = EmailText.objects.get(email_case='Reviewed and (will not fix, or duplicate, or not an error, or major book revision)')
            subject = email_text.email_subject_text
            body = email_text.email_body_text
            send_email = True
        elif instance.status == 'Reviewed' and instance.resolution == 'Approved':
            email_text = EmailText.objects.get(email_case='Reviewed and Approved')
            subject = email_text.email_subject_text
            body = email_text.email_body_text
            send_email = True
        elif instance.status == 'Completed' and instance.resolution == 'Sent to Customer Support':
            email_text = EmailText.objects.get(email_case='Completed and Sent to Customer Support')
            subject = email_text.email_subject_text
            body = email_text.email_body_text
            send_email = True
            override_to = True
            to = "*****@*****.**"
        elif instance.resolution == 'More Information Requested':
            email_text = EmailText.objects.get(email_case='More Information Requested')
            subject = email_text.email_subject_text
            body = email_text.email_body_text
            send_email = True

        if not override_to:
            if instance.submitted_by_account_id:
                user = get_user_info(instance.submitted_by_account_id)
                to = user['email']
            elif instance.submitter_email_address:
                to = instance.submitter_email_address
            elif instance.submitted_by:
                to = instance.submitted_by.email
            else:
                send_email = False

        if send_email:
            errata_email_info = {
                'subject': subject,
                'body': body,
                'status': "In review",
                'resolution': instance.resolution,
                'created': created,
                'id': instance.id,
                'title': instance.openstax_book,
                'source': instance.resource,
                'error_type': instance.error_type,
                'location': instance.location,
                'description': instance.detail,
                'date_submitted': instance.created,
                'host': settings.HOST_LINK,
            }
            msg_plain = render_to_string('templates/email.txt', errata_email_info)
            msg_html = render_to_string('templates/email.html', errata_email_info)

            send_mail(
                subject,
                msg_plain,
                '*****@*****.**',
                [to],
                html_message=msg_html,
            )
예제 #6
0
 def user_faculty_status(self):
     try:
         user = get_user_info(self.submitted_by_account_id)
         return user['faculty_status']
     except:
         return None
예제 #7
0
 def user_name(self):
     try:
         user = get_user_info(self.submitted_by_account_id)
         return user['fullname']
     except:
         return None
예제 #8
0
 def user_email(self):
     try:
         user = get_user_info(self.submitted_by_account_id)
         return user['email']
     except:
         return None
예제 #9
0
 def fullname(self):
     try:
         user = get_user_info(self.account_id)
         return user['fullname']
     except:
         return None
예제 #10
0
def send_status_update_email(sender, instance, created, **kwargs):
        send_email = False
        override_to = False
        if created:
            subject = "We received your submission"
            body = "Thanks for your help! Your errata submissions help keep OpenStax resources high quality and up to date."
            send_email = True
        elif instance.status == 'Reviewed' and (instance.resolution == 'Will Not Fix' or instance.resolution == 'Duplicate' or instance.resolution == 'Not An Error' or instance.resolution == 'Major Book Revision'):
            subject = "We reviewed your erratum suggestion"
            body = "Thanks again for your submission. Our reviewers have evaluated it and have determined there will be no change made."
            send_email = True
        elif instance.status == 'Reviewed' and instance.resolution == 'Approved':
            subject = "We received your submission"
            body = "Thanks again for your submission. Our reviewers have evaluated it and have determined that a change will be made. We will email you again when the appropriate resource has been updated."
            send_email = True
        elif instance.status == 'Completed' and instance.resolution == 'Approved':
            subject = "Your correction is live"
            body = "The correction you suggested has been incorporated into the appropriate OpenStax resource. Thanks for your help!"
            send_email = True
        elif instance.status == 'Completed' and instance.resolution == 'Sent to Customer Support':
            subject = "Errata report for Customer Support"
            body = "An errata report has been submitted that requires customer support attention."
            send_email = True
            override_to = True
            to = "*****@*****.**"
        elif instance.resolution == 'More Information Requested':
            subject = "More information requested on your errata report"
            body = "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."
            send_email = True

        if not override_to:
            if instance.submitted_by_account_id:
                user = get_user_info(instance.submitted_by_account_id)
                to = user['email']
            elif instance.submitter_email_address:
                to = instance.submitter_email_address
            elif instance.submitted_by:
                to = instance.submitted_by.email
            else:
                send_email = False

        if send_email:
            errata_email_info = {
                'subject': subject,
                'body': body,
                'status': "In review",
                'resolution': instance.resolution,
                'created': created,
                'id': instance.id,
                'title': instance.book.title,
                'source': instance.resource,
                'error_type': instance.error_type,
                'location': instance.location,
                'description': instance.detail,
                'date_submitted': instance.created,
                'host': settings.HOST_LINK,
            }
            msg_plain = render_to_string('templates/email.txt', errata_email_info)
            msg_html = render_to_string('templates/email.html', errata_email_info)

            send_mail(
                subject,
                msg_plain,
                '*****@*****.**',
                [to],
                html_message=msg_html,
            )
예제 #11
0
 def test_user_data_returns_false_when_invalid(self):
     user_data = get_user_info('asdf')
     self.assertEqual(user_data, False)
예제 #12
0
 def test_user_info_returns_false_with_no_uid(self):
     user_data = get_user_info()
     self.assertEqual(user_data, False)
예제 #13
0
 def test_can_get_user_info(self):
     user_data = get_user_info(2)
     self.assertNotEqual(user_data, False)