Repository: learningequality/kolibri

Issue:
Can change username with duplicates
<!--
Instructions:
 * Fill out the sections below, replace …'s with information about your issue
 * Use the 'preview' function above this text box to verify formatting before submitting
-->

### Observed behavior
<!--
Description of the behavior that was observed, including screenshots or other references when applicable
-->

I was sure I fixed the issue before. It's now reoccurring as seen below:

![bug](https://user-images.githubusercontent.com/27984604/37702097-70a3bfd4-2d2c-11e8-90fc-89ea907d1b47.gif)

 
![screen shot 2018-03-21 at 5 27 13 pm](https://user-images.githubusercontent.com/27984604/37702338-247c7d3e-2d2d-11e8-8e41-1850fca15945.png)


### Expected behavior
<!--
Description of what behavior was expected but did not occur
-->

Should throw an error that says username already exists

### User-facing consequences
<!--
Implications and real-world consequences for learners, coaches, admins, and other users of the application
-->

Can't login?

### Errors and logs
<!--
Relevant logs from:
 * the command line
 * ~/.kolibri/kolibri.log
 * the browser console

Please wrap errors in triple backticks for clean formatting like this:
```
01:10 info: something happened
01:12 error: something bad happened
```
-->

### Steps to reproduce
<!--
Precise steps that someone else can follow in order to see this behavior
-->


### Context
<!--
Tell us about your environment, including:
 * Kolibri version
 * Operating system
 * Browser
-->

Kolibri version: develop

Same username suggestion while signing-in (case-sensitive feature not accounted for) after the user edits a name using the edit username feature.
### Observed behavior
When the user edits the username from his/her profile and then again tries to login, there can be 2 suggestions of same username based on case-sensitive nature, for eg sahilm, sahilM

### Expected behavior

The username must not be allowed to be the same (as mentioned in #3458) and suggestions must not be case-sensitive nature, for eg sahilm and sahilM cannot exist simultaneously.

### User-facing consequences
It would create confusion in the classroom if the students are shown same username.

### Errors and logs

![screenshot from 2018-04-05 09 28 08](https://user-images.githubusercontent.com/38091824/38346997-16e3d8c2-38b6-11e8-9eaf-06fd2bbe375f.png)

![screenshot from 2018-04-05 09 42 44](https://user-images.githubusercontent.com/38091824/38346963-ef6fbe1e-38b5-11e8-80f6-d91032820fe8.png)


### Steps to reproduce

1. Login as admin and give permission to the users to edit the username.
2. Login as a user and edit the username which is same as existing but has different cases, like abc1, ABC1.
3. Try to sign in as user and look for suggestions which will be same with different cases.

### Context

Kolibri version : kolibri 0.9.0
Operating system : ubuntu 14.04
Browser : Chrome

### Screenshot
![screenshot from 2018-04-05 09 42 44](https://user-images.githubusercontent.com/38091824/38347147-3624cccc-38b7-11e8-8f7b-ae3aa681a31c.png)
![screenshot from 2018-04-05 09 16 21](https://user-images.githubusercontent.com/38091824/38347149-44fe7e6e-38b7-11e8-8e53-303a9a14f914.png)
![screenshot from 2018-04-05 09 22 09](https://user-images.githubusercontent.com/38091824/38347177-81abd1c2-38b7-11e8-9dc5-d0c416c18ee5.png)





Discussion:

@mrpau-eugene 

Resolving patch:
diff --git a/kolibri/auth/serializers.py b/kolibri/auth/serializers.py
--- a/kolibri/auth/serializers.py
+++ b/kolibri/auth/serializers.py
@@ -42,6 +42,11 @@ def create(self, validated_data):
             raise serializers.ValidationError(_('An account with that username already exists'))
         return super(FacilityUserSerializer, self).create(validated_data)
 
+    def update(self, instance, validated_data):
+        if validated_data.get('username') and FacilityUser.objects.exclude(id__exact=instance.id).filter(username__iexact=validated_data['username']).exists():
+            raise serializers.ValidationError(_('An account with that username already exists'))
+        return super(FacilityUserSerializer, self).update(instance, validated_data)
+
 
 class FacilityUserSignupSerializer(FacilityUserSerializer):
 


Test patch: