Example #1
0
def test_has_superuser_access(app, client, user_without_role, superuser):
    """Test if user has a super admin access."""
    app.config.update(SONAR_APP_DISABLE_PERMISSION_CHECKS=True)
    assert has_superuser_access()

    app.config.update(SONAR_APP_DISABLE_PERMISSION_CHECKS=False)
    login_user_via_view(client,
                        email=user_without_role.email,
                        password='******')

    assert not has_superuser_access()

    client.get(url_for_security('logout'))

    login_user_via_view(client, email=superuser['email'], password='******')

    assert has_superuser_access()
Example #2
0
def can_activate_mode(value):
    """Check if current user can activate `shared` or `dedicated` mode.

    If the value is set to False, validation passed because the mode is not
    activated.

    :param value: Boolean value posted.
    :returns: True if property can be modified
    """
    return not value or has_superuser_access()
Example #3
0
    def override_modes(self, data, **kwargs):
        """Override organisation's modes.

        For non super users, the modes (isShared, isDedicated) is not saved
        by posting the data, but guessed from user's organisation.
        """
        if not has_superuser_access():
            data['isShared'] = current_organisation.get('isShared', False)
            data['isDedicated'] = current_organisation.get(
                'isDedicated', False)
        return data