Ejemplo n.º 1
0
    def test_permission_hash_after_modification(self):
        revoke_permission(self.user, 'permission3')

        perm_hash = available_perm_status(self.user)

        self.assertFalse(perm_hash['permission3'])
        self.assertFalse(perm_hash['permission4'])
    def test_permission_hash_after_modification(self):
        revoke_permission(self.user, "permission3")

        perm_hash = available_perm_status(self.user)

        self.assertFalse(perm_hash["permission3"])
        self.assertFalse(perm_hash["permission4"])
Ejemplo n.º 3
0
def index(request):
    template = loader.get_template('website/index.html')
    context = {}
    if request.user.is_authenticated():
        context['role'] = get_user_role(request.user).get_name()
        context['permissions'] = available_perm_status(request.user)
    return HttpResponse(template.render(context, request))
Ejemplo n.º 4
0
def users(request):
    result = []
    for user in User.objects.all():
        if get_user_role(user) is None:
            result.append((user, None, None))
        else:
            result.append(
                (user, get_user_role(user), available_perm_status(user)))
    return render(request, 'users.html', {'result': result})
Ejemplo n.º 5
0
    def get(self, request, *args, **kwargs):
        """
        Handle GET requests to templates using React
        """
        user = request.user
        username = get_social_username(user)
        name = ""
        roles = []
        if not user.is_anonymous():
            name = user.profile.preferred_name
            roles = [{
                'program':
                role.program.id,
                'role':
                role.role,
                'permissions': [
                    perm
                    for perm, value in available_perm_status(user).items()
                    if value is True
                ]
            } for role in user.role_set.all()]

        js_settings = {
            "gaTrackingID": settings.GA_TRACKING_ID,
            "reactGaDebug": settings.REACT_GA_DEBUG,
            "authenticated": not user.is_anonymous(),
            "name": name,
            "username": username,
            "host": webpack_dev_server_host(request),
            "edx_base_url": settings.EDXORG_BASE_URL,
            "roles": roles,
            "search_url": reverse('search_api', kwargs={"elastic_url": ""}),
        }

        return render(request,
                      "dashboard.html",
                      context={
                          "style_src": get_bundle_url(request, "style.js"),
                          "dashboard_src":
                          get_bundle_url(request, "dashboard.js"),
                          "js_settings_json": json.dumps(js_settings),
                      })
Ejemplo n.º 6
0
    def test_roles_setting(self):
        """
        Assert SETTINGS when a user has roles assigned to them
        """
        profile = self.create_and_login_user()

        Role.objects.create(
            program=ProgramFactory.create(),
            user=profile.user,
            role=Role.DEFAULT_ROLE,
        )

        resp = self.client.get(DASHBOARD_URL)
        js_settings = json.loads(resp.context['js_settings_json'])
        assert js_settings['roles'] == [{
            'program':
            role.program.id,
            'role':
            role.role,
            'permissions': [
                key
                for key, value in available_perm_status(profile.user).items()
            ],
        } for role in profile.user.role_set.all()]
Ejemplo n.º 7
0
    def test_permission_hash(self):
        perm_hash = available_perm_status(self.user)

        self.assertTrue(perm_hash['permission3'])
        self.assertFalse(perm_hash['permission4'])
    def test_permission_hash(self):
        perm_hash = available_perm_status(self.user)

        self.assertTrue(perm_hash["permission3"])
        self.assertFalse(perm_hash["permission4"])