Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix perms instructor certificates #257

Merged

Conversation

melvinsoft
Copy link

@melvinsoft melvinsoft commented Jul 26, 2018

The Certificates tab in the Instructor dashboard (and all the action) require global staff permissions, which doesn't makes sense with the rest of the Instructor dashboard architecture. The permissions check is always if the user is staff in the course, not global.

This bug came up in Tahoe since none of our users have global staff, but it's affecting other customers as well, also this is something we should push upstream.

Copy link

@bryanlandia bryanlandia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @melvinsoft - looks great. A couple things:

Please add another test method below here:

def test_visible_only_to_global_staff(self):

to check for the non-global staff condition. Also, I wonder if there are business reasons edX has chosen global staff only. What do you think?

I checked, and this functionality hasn't changed at HEAD of edx/master so yeah, probably a good candidate for upstream.

@melvinsoft
Copy link
Author

melvinsoft commented Jul 31, 2018

@bryanlandia Thanks for reviewing the PR. I've asked in the #general channel in edX slack, but I didn't received a response yet.

I'm gonna wait one more day and then ping again.

@OmarIthawi
Copy link

That's a huge change @melvinsoft. While it might work fine, but I think we should think twice before getting it merged.

Please also fix the import, otherwise courseware won't work: from util.views import require_global_staff like this:

13:05:36 omar@oryx:edx-platform $ git diff
diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py
index 73357f9..970f3dd 100644
--- a/lms/djangoapps/courseware/views/views.py
+++ b/lms/djangoapps/courseware/views/views.py
@@ -33,7 +33,7 @@ from opaque_keys import InvalidKeyError
 from opaque_keys.edx.keys import CourseKey, UsageKey
 from opaque_keys.edx.locations import SlashSeparatedCourseKey
 from rest_framework import status
-from lms.djangoapps.instructor.views.api import require_global_staff
+from util.views import require_global_staff
 from lms.djangoapps.ccx.utils import prep_course_for_grading
 from lms.djangoapps.grades.new.course_grade import CourseGradeFactory
 from lms.djangoapps.instructor.enrollment import uses_shib

There's also the unpleasant fact that tests are failing:

$ paver test_system --disable-migrations --fasttest -t lms/djangoapps/instructor/tests/test_certificates.py --nologcapture

Succeeds without your change, all the 49. When adding the changes in this PR, 4 tests fails:

test_certificate_generation_api_without_global_staff
test_allow_only_global_staff
test_visible_only_to_global_staff

Could you please check them?

Copy link

@OmarIthawi OmarIthawi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @melvinsoft! Please consider fixing the tests, and the import issue.

@@ -35,7 +35,6 @@
FileValidationException, UniversalNewlineIterator
)
from util.json_request import JsonResponse, JsonResponseBadRequest
from util.views import require_global_staff

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line breaks the expectations in lms/djangoapps/courseware/views/views.py, please consider keeping it.

@OmarIthawi
Copy link

Bryan: to check for the non-global staff condition. Also, I wonder if there are business reasons edX has chosen global staff only. What do you think?

@bryanlandia @melvinsoft I thought that edX chose that for a business reason also, but looking at both of the:

There seem to be nothing about which staff to use.

@OmarIthawi
Copy link

@melvinsoft Update: edX engineer Saleem Latif have just replied and it looks like our change is fine. I'm going to do a final test and mark this PR as ✔️

Copy link

@OmarIthawi OmarIthawi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@melvinsoft Thanks for catching the error and fixing it.

If the change works for AMC, please merge it. Let's please consider contributing this upstream. It looks like an easy one.

@@ -53,6 +53,7 @@ def setUp(self):
super(CertificatesInstructorDashTest, self).setUp()
self.global_staff = GlobalStaffFactory()
self.instructor = InstructorFactory(course_key=self.course.id)
self.staff = StaffFactory(course_key=self.course.id)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StaffFactory is not imported. Tests are still broken.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OmarIthawi this line is still broken, right?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@melvinsoft take another look when you get a chance.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bryanlandia @OmarIthawi import fixed! Sorry I cannot run tests properly on the AMC devstack ATM. Please give it another try and let me know.

@melvinsoft
Copy link
Author

@bryanlandia @OmarIthawi Thanks for all your efforts here! Much appreciated! I've fixed the tests, but I cannot try them in my devstack, please let me know if it works to you, and if everything looks good, I'm going to squash and rebase the PR before merge. Thanks again!

@OmarIthawi
Copy link

OmarIthawi commented Aug 9, 2018

@melvinsoft It fixes part of the broken tests, but not all of them.

Please consider having the latest edX docker devstack so you can run tests on. Having the tests fail quickly is better than waiting for someone else to report.

@melvinsoft
Copy link
Author

@OmarIthawi @bryanlandia I tried to run the tests in a new docker devstack, and they're still failing. We need to deliver this to the customer, so we've two options:

  • Some of you volunteer to fix the tests and merge this.
  • We merge it and we create some tech debt, with a card to address it as soon as we can.

Please let me know.

@OmarIthawi
Copy link

We merge it and we create some tech debt, with a card to address it as soon as we can.

@melvinsoft We create tech debt regularly so this won't be an issue.

However, the fact that tests are failing, could mean an actual bug being pushed to production.

It depends on how much you'd like to ensure that another bug isn't happening. Both manual and automated tests work equally in this case.

If you think it's ready, please feel free to deploy.

@melvinsoft
Copy link
Author

@OmarIthawi Thanks! but I did one more effort, and I run the test, cherrypicking the commits, and I was able to fix them. Can you do a final review over the changes? // cc @bryanlandia

Thanks!

Copy link

@OmarIthawi OmarIthawi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@melvinsoft Thanks for taking the extra efforts. This is really helpful for maintenance in the future.

Please address the the issue below, and feel free to merge.

@@ -284,25 +296,6 @@ def _assert_redirects_to_instructor_dash(self, response):
expected_redirect += '#view-certificates'
self.assertRedirects(response, expected_redirect)

def test_certificate_generation_api_without_global_staff(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the test back, I've fixed it:

    def test_certificate_generation_api_without_global_staff(self):
        """
        Test certificates generation api endpoint returns permission denied if
        user who made the request is not member of global staff.
        """
        user = UserFactory.create()
        self.client.login(username=user.username, password='test')
        url = reverse(
            'start_certificate_generation',
            kwargs={'course_id': unicode(self.course.id)}
        )
        response = self.client.post(url)
        self.assertEqual(response.status_code, 403)
        self.client.login(username=self.instructor.username, password='test')
        response = self.client.post(url)
        self.assertEqual(response.status_code, 200)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks omar! Test added!

@OmarIthawi OmarIthawi dismissed bryanlandia’s stale review September 19, 2018 06:32

No longer applicable. Thanks Bryan!

…or dashboard

change all require_global_staff for require_level

fix tests and import

fix import in test for StaffFactory

fix more tests

fix test
@melvinsoft melvinsoft force-pushed the bugfix/fix-perms-instructor-certificates branch from f288e44 to 1262ba9 Compare September 19, 2018 15:29
@melvinsoft
Copy link
Author

Commits squashed!

@melvinsoft melvinsoft merged commit a297ea0 into appsembler/amc/develop Sep 19, 2018
@OmarIthawi OmarIthawi deleted the bugfix/fix-perms-instructor-certificates branch November 12, 2019 14:54
shadinaif pushed a commit that referenced this pull request Nov 16, 2022
Per 12. Make your fix public. 
I am merging this fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants