Example #1
0
    def initialize(self, record_owner_name=None):
        # initialize a few helpful variables here
        self.record_viewer = self.request.user

        self.record_owner = None
        if record_owner_name:
            self.record_owner = get_object_or_404(User,
                                                  username=record_owner_name)

        # Is the current user faculty or a CCNMTL staff member
        self.is_viewer_faculty = cached_course_is_faculty(self.request.course,
                                                          self.record_viewer)

        # Can the record_owner edit the records
        self.viewing_own_records = (self.record_owner == self.record_viewer)
        self.viewing_faculty_records = (
            self.record_owner and
            cached_course_is_faculty(self.request.course, self.record_owner))

        # Does the course allow viewing other user selections?
        # The viewer can always view their own records + faculty records
        # If the viewer is faculty, they can view all records
        self.all_selections_are_visible = \
            all_selections_are_visible(self.request.course)
        self.all_items_are_visible = \
            all_items_are_visible(self.request.course)

        self.visible_authors = []
        if (not self.is_viewer_faculty and
                (not self.all_selections_are_visible or
                 not self.all_items_are_visible)):
            self.visible_authors = [self.record_viewer.id]  # me
            for user in self.request.course.faculty.all():
                self.visible_authors.append(user.id)
Example #2
0
    def initialize(self, record_owner_name=None):
        # initialize a few helpful variables here
        self.record_viewer = self.request.user

        self.record_owner = None
        if record_owner_name:
            self.record_owner = get_object_or_404(User,
                                                  username=record_owner_name)

        # Is the current user faculty or a CCNMTL staff member
        self.is_viewer_faculty = cached_course_is_faculty(self.request.course,
                                                          self.record_viewer)

        # Can the record_owner edit the records
        self.viewing_own_records = (self.record_owner == self.record_viewer)
        self.viewing_faculty_records = (
            self.record_owner and
            cached_course_is_faculty(self.request.course, self.record_owner))

        # Does the course allow viewing other user selections?
        # The viewer can always view their own records + faculty records
        # If the viewer is faculty, they can view all records
        self.all_selections_are_visible = \
            all_selections_are_visible(self.request.course)
        self.all_items_are_visible = \
            all_items_are_visible(self.request.course)

        self.visible_authors = []
        if (not self.is_viewer_faculty and
                (not self.all_selections_are_visible or
                 not self.all_items_are_visible)):
            self.visible_authors = [self.record_viewer.id]  # me
            for user in self.request.course.faculty.all():
                self.visible_authors.append(user.id)
Example #3
0
    def has_object_permission(self, request, view, obj):
        # Am I the owner of this asset?
        if obj.author == request.user:
            return True

        if cached_course_is_faculty(obj.course, request.user):
            return True

        if not all_items_are_visible(obj.course):
            raise PermissionDenied

        return True
Example #4
0
 def __init__(self, *args, **kwargs):
     r = super(DashboardSettingsForm, self).__init__(*args, **kwargs)
     self.fields['publish_to_world'].initial = \
         allow_public_compositions(self.instance)
     self.fields['see_eachothers_items'].initial = \
         all_items_are_visible(self.instance)
     self.fields['see_eachothers_selections'].initial = \
         all_selections_are_visible(self.instance)
     self.fields['allow_item_download'].initial = \
         allow_item_download(self.instance)
     self.fields['allow_roster_changes'].initial = \
         allow_roster_changes(self.instance)
     return r
Example #5
0
 def __init__(self, *args, **kwargs):
     r = super(DashboardSettingsForm, self).__init__(*args, **kwargs)
     self.fields['publish_to_world'].initial = \
         allow_public_compositions(self.instance)
     self.fields['homepage_title'].initial = \
         course_information_title(self.instance)
     self.fields['see_eachothers_items'].initial = \
         all_items_are_visible(self.instance)
     self.fields['see_eachothers_selections'].initial = \
         all_selections_are_visible(self.instance)
     self.fields['allow_item_download'].initial = \
         allow_item_download(self.instance)
     self.fields['allow_roster_changes'].initial = \
         allow_roster_changes(self.instance)
     return r
Example #6
0
    def test_post_disabled_selection_visibility(self):
        self.client.login(username=self.instructor_one.username,
                          password='******')
        data = {course_details.ITEM_VISIBILITY_KEY: 0}

        response = self.client.post('/dashboard/settings/', data)
        self.assertEquals(response.status_code, 302)

        # unchanged from defaults
        self.assertEquals(course_information_title(self.sample_course),
                          'From Your Instructor')
        self.assertFalse(allow_public_compositions(self.sample_course))

        # updated
        self.assertFalse(all_items_are_visible(self.sample_course))
        self.assertFalse(all_selections_are_visible(self.sample_course))
Example #7
0
    def test_post(self):
        self.assertTrue(
            self.client.login(username=self.instructor_one.username,
                              password='******'))
        data = {
            course_details.COURSE_INFORMATION_TITLE_KEY: "Foo",
            course_details.SELECTION_VISIBILITY_KEY: 0,
            course_details.ITEM_VISIBILITY_KEY: 0,
            course_details.ALLOW_PUBLIC_COMPOSITIONS_KEY: 1
        }

        response = self.client.post('/dashboard/settings/', data)
        self.assertEquals(response.status_code, 302)
        self.assertEquals(course_information_title(self.sample_course), "Foo")
        self.assertTrue(allow_public_compositions(self.sample_course))
        self.assertFalse(all_items_are_visible(self.sample_course))
        self.assertFalse(all_selections_are_visible(self.sample_course))
Example #8
0
    def __init__(self, *args, **kwargs):
        r = super(DashboardSettingsForm, self).__init__(*args, **kwargs)
        self.fields['publish_to_world'].initial = \
            allow_public_compositions(self.instance)
        self.fields['homepage_title'].initial = \
            course_information_title(self.instance)
        self.fields['see_eachothers_items'].initial = \
            all_items_are_visible(self.instance)
        self.fields['see_eachothers_selections'].initial = \
            all_selections_are_visible(self.instance)
        self.fields['allow_item_download'].initial = \
            allow_item_download(self.instance)
        lti_context = LTICourseContext.objects.filter(
            group=self.instance.group.id,
            faculty_group=self.instance.faculty_group.id).first()
        self.fields['lti_integration'].initial = \
            (lti_context and lti_context.enable)

        return r
 def all_items_are_visible(self):
     # default
     self.assertFalse(all_items_are_visible(self.sample_course))
Example #10
0
 def all_items_are_visible(self):
     # default
     self.assertFalse(all_items_are_visible(self.sample_course))