Repository: learningequality/kolibri

Issue:
Not able to Import Facility through Advanced setup on Kolibri
### Observed behavior
While configuring Kolibri app through Advanced setup, User is not able to import facility as the facilities available to be imported are not clickable/[selectable](https://github.com/learningequality/kolibri/blob/release-v0.14.x/integration_testing/features/super-admin/super-admin-imports-facility-in-device-setup.feature).
…

### Expected behavior
User should be able to import selected Facility through Advanced setup on Kolibri.
…

### User-facing consequences
User will not be able to proceed further and is blocked from using the application.

…

### Errors and logs



```

```

…

### Steps to reproduce
1. Double click on Kiolibri.exe file.
2. Application window will open asking to select a language.
3. Select a Language and proceed.
4. Select Advanced setup and proceed.
5. Select Import Facility Option and enter the network address on the next window.
6. User should be able to connect to the above provided network.
7. Try to import any of the facilities  available under that network.
8. Observe that user is not select any of the facility neither by mouse nor by keyboard.

PFA the video for reference.
[AdvancedSetup_issue.zip](https://github.com/learningequality/kolibri/files/5414227/AdvancedSetup_issue.zip)


…

### Context

Tell us about your environment, including:
 * Kolibri version 0.14.3
 * Operating system Windows 10
 * Browser: IE11

…



Discussion:

Resolving patch:
diff --git a/kolibri/core/auth/api.py b/kolibri/core/auth/api.py
--- a/kolibri/core/auth/api.py
+++ b/kolibri/core/auth/api.py
@@ -15,10 +15,12 @@
 from django.contrib.auth.models import AnonymousUser
 from django.core.exceptions import ObjectDoesNotExist
 from django.db import transaction
+from django.db.models import Func
 from django.db.models import OuterRef
 from django.db.models import Q
 from django.db.models import Subquery
 from django.db.models import TextField
+from django.db.models import Value
 from django.db.models.functions import Cast
 from django.db.models.query import F
 from django.http import Http404
@@ -355,7 +357,13 @@ def annotate_queryset(self, queryset):
             .annotate(
                 last_synced=Subquery(
                     TransferSession.objects.filter(
-                        filter=Cast(OuterRef("dataset"), TextField())
+                        filter=Func(
+                            Cast(OuterRef("dataset"), TextField()),
+                            Value("-"),
+                            Value(""),
+                            function="replace",
+                            output_field=TextField(),
+                        )
                     )
                     .order_by("-last_activity_timestamp")
                     .values("last_activity_timestamp")
diff --git a/kolibri/core/discovery/utils/filesystem/posix.py b/kolibri/core/discovery/utils/filesystem/posix.py
--- a/kolibri/core/discovery/utils/filesystem/posix.py
+++ b/kolibri/core/discovery/utils/filesystem/posix.py
@@ -43,6 +43,7 @@
         "ecryptfs",
         "fuse",
         "fuse.gvfsd-fuse",
+        "fuse.portal",
         "fusectl",
         "hugetlbfs",
         "mqueue",
@@ -116,7 +117,12 @@ def get_drive_list():
             continue
 
         # attempt to get some additional metadata about the drive
-        usage = _get_drive_usage(path)
+        try:
+            usage = _get_drive_usage(path)
+        except OSError:
+            # skip if we don't have access to get drive usage
+            continue
+
         dbus_drive_info = _try_to_get_drive_info_from_dbus(drive["device"])
         diskutil_info = _try_to_get_drive_info_from_diskutil(drive["device"])
 


Test patch:
diff --git a/kolibri/core/auth/test/test_data_migrations.py b/kolibri/core/auth/test/test_data_migrations.py
--- a/kolibri/core/auth/test/test_data_migrations.py
+++ b/kolibri/core/auth/test/test_data_migrations.py
@@ -1,6 +1,7 @@
-import os
 import unittest
 
+from django.conf import settings
+
 from kolibri.core.auth.constants.role_kinds import ADMIN
 from kolibri.core.auth.models import Classroom
 from kolibri.core.auth.models import Facility
@@ -9,7 +10,8 @@
 
 
 @unittest.skipIf(
-    os.environ.get("TOX_ENV") == "postgres",
+    getattr(settings, "DATABASES")["default"]["ENGINE"]
+    == "django.db.backends.postgresql",
     "Skipping postgres due to unsupported upgrade",
 )
 class MultipleCollectionTestCase(TestMigrations):
diff --git a/kolibri/deployment/default/settings/postgres_test.py b/kolibri/deployment/default/settings/postgres_test.py
--- a/kolibri/deployment/default/settings/postgres_test.py
+++ b/kolibri/deployment/default/settings/postgres_test.py
@@ -20,15 +20,19 @@
     "default": {
         "ENGINE": "django.db.backends.postgresql",
         "USER": "postgres",
-        "PASSWORD": "",
+        "PASSWORD": "postgres",
         "NAME": os.environ.get("POSTGRES_DB") or "default",  # noqa
-        "TEST": {"NAME": "travis_ci_default"},
+        "HOST": "localhost",
+        "PORT": "5432",
+        "TEST": {"NAME": "test"},
     },
     "default-serializable": {
         "ENGINE": "django.db.backends.postgresql",
         "USER": "postgres",
-        "PASSWORD": "",
+        "PASSWORD": "postgres",
         "NAME": os.environ.get("POSTGRES_DB") or "default",  # noqa
+        "HOST": "localhost",
+        "PORT": "5432",
         "OPTIONS": {"isolation_level": isolation_level},
         "TEST": {"MIRROR": "default"},
     },
diff --git a/test/conditional/test_build.sh b/test/conditional/test_build.sh
deleted file mode 100755
--- a/test/conditional/test_build.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/bash
-
-set -e
-
-PREVIOUS_CWD=`pwd`
-
-# Goto location of this script
-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-cd "$DIR/../../"
-
-# Install build deps
-pip install -r requirements/build.txt
-pip install -r requirements/test.txt
-
-# Build .whl
-yarn install
-make dist > /dev/null
-pip install dist/kolibri*.whl
-
-cd "$PREVIOUS_CWD"
-
-exit 0
diff --git a/test/if.sh b/test/if.sh
deleted file mode 100755
--- a/test/if.sh
+++ /dev/null
@@ -1,149 +0,0 @@
-#!/bin/bash
-
-# This script is invoked by Travis testing and inspects
-# the changeset that's being built.
-#
-# Usage:
-#
-#    if.sh <label> && something_else
-#
-# The intention is to be able to ONLY test certain aspects
-# when special conditions are satisfied.
-#
-# Notes:
-#    JS tests are expected to be very fast
-#    We shouldn't skip tests when it affects Coverage negatively
-#    We can possibly do tests based on which branch is pushed to
-#
-# https://github.com/learningequality/kolibri/issues/27
-#
-# What changes are analyzed?
-#
-# For this script, we should mainly use Travis' env
-# $TRAVIS_COMMIT_RANGE. The reason is simple: You cannot tell what
-# changes have been implemented since last test, thus if your
-# condtion should fire or not.
-#
-# Definition:
-# TRAVIS_COMMIT_RANGE: The range of commits that were included in
-# the push or pull request.
-#
-# https://docs.travis-ci.com/user/environment-variables/
-
-
-set -e
-
-# Goto location of this script
-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-cd $DIR
-
-# Traceback utility for Bash
-. "$DIR/traceback.sh"
-
-LABEL="$1"
-
-FORCE_RUN="$2"
-
-# Set by Travis CI
-commit="$TRAVIS_COMMIT"
-current_branch="$TRAVIS_BRANCH"
-
-git_changeset=""
-
-if [ "$TRAVIS_BRANCH" == "" ]
-then
-    # The changeset is $TRAVIS_COMMIT_RANGE
-    # echo "Using TRAVIS_COMMIT_RANGE as changeset"
-    git_changeset=`git show --name-only --no-notes --oneline $TRAVIS_COMMIT_RANGE`
-else
-    # The changeset is the diff between PR and branch that the PR is made
-    # against.
-    # echo "Using git log $TRAVIS_BRANCH..HEAD as changeset"
-    # Because Travis' git clone does not contain the upstream branch being
-    # PR'ed against, we need to explicitly fetch it and compare the FETCH_HEAD
-    # in which it's stored with the detached head.
-    git fetch origin $TRAVIS_BRANCH
-    git_changeset=`git log FETCH_HEAD --oneline --name-only`
-fi
-
-# echo "Travis branch / branch merging into: $TRAVIS_BRANCH"
-# echo "Git change set:\n\n$git_changeset"
-
-function match_changes {
-    if ! [ "$FORCE_RUN" == "" ]
-    then
-        return 0
-    fi
-    # Usage: match_changes "match1" "match2"
-    # if branch should always be tested
-    if [ "$TRAVIS_PULL_REQUEST" == "false" ]
-    then
-        for branch in releases/*
-        do
-            if echo "$current_branch" | grep -q "$branch"
-            then
-                # echo "Always testing $branch, so not skipping $LABEL..."
-                return 0
-            fi
-        done
-    fi
-
-    # Loop through all arguments
-    for pattern_to_match
-    do
-        if echo "$git_changeset" | grep -q "$pattern_to_match"
-        then
-            # echo "Conditional match for pattern '$pattern_to_match'"
-            return 0
-        fi
-    done
-
-    # No matches
-    return 1
-}
-
-
-# If something changes that's related to our sdist packaging
-# or installation mechanism, then we build and install.
-if [[ "$LABEL" == "setup_changed" ]]
-then
-
-    # Match with commit messages containing "[ setup ]"
-    # Match commits changing requirements.txt
-    # Match commits changing setup.py
-    if match_changes "\[\s*setup\s*\]" \
-                     "^setup\.py" \
-                     "^requirements" \
-                     "^Makefile" \
-                     "^MANIFEST*" \
-       && true # <- because of set -e
-    then
-
-        . conditional/test_build.sh
-
-    fi
-
-fi
-
-# If something changes that's related to our sdist packaging
-# or installation mechanism, then we build and install.
-if [[ "$LABEL" == "requirements_changed" ]]
-then
-
-    # Match with commit messages containing "[ license ]"
-    # Match commits changing requirements.txt
-    if match_changes "\[\s*license\s*\]" \
-                     "^requirements" \
-       && true # <- because of set -e
-    then
-
-        echo "Requirements changed, checking license info..."
-        . conditional/test_licenses.sh
-
-    fi
-
-fi
-
-# No matches
-echo "[ OK ] Skipping conditional test '$LABEL'"
-exit 0