Skip to content

Commit

Permalink
Merge pull request #2492 from rtibbles/0.4into0.5
Browse files Browse the repository at this point in the history
0.4 into 0.5 and prep for 0.5.2
  • Loading branch information
rtibbles committed Oct 20, 2017
2 parents 3176aa4 + 7427580 commit 4944d93
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 6 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ Release Notes
Changes are ordered reverse-chronologically.


0.5.2
-----

- Release bug fix from 0.4.7


0.5.1
------------------
-----

- Python dependencies: Only bundle, do not install dependencies in system env #2299
- Beta Android support
Expand All @@ -29,6 +35,12 @@ Changes are ordered reverse-chronologically.
- KOLIBRI_LISTEN_PORT environment variable for specifying a default for the --port option #1724


0.4.7
-----

- Fix bug that made updating existing Django models from the frontend impossible


0.4.6
-----

Expand Down
23 changes: 19 additions & 4 deletions kolibri/auth/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .constants import role_kinds
from .models import Classroom, DeviceOwner, Facility, FacilityDataset, FacilityUser, LearnerGroup, Membership, Role


class RoleSerializer(serializers.ModelSerializer):

class Meta:
Expand All @@ -24,10 +25,24 @@ def update(self, instance, validated_data):
else:
return super(BaseKolibriUserSerializer, self).update(instance, validated_data)

def validate_username(self, value):
if FacilityUser.objects.filter(username__iexact=value).exists() | DeviceOwner.objects.filter(username__iexact=value).exists():
raise serializers.ValidationError(_('An account with that username already exists'))
return value
def validate(self, data):
username = data.get('username', None)
# Only avoid checking against own username if this user already exists.
user_id = self.instance.id if self.instance else None

if username:
facility_user_query = FacilityUser.objects.filter(username__iexact=username)
device_owner_query = DeviceOwner.objects.filter(username__iexact=username)

if user_id:
facility_user_query = facility_user_query.exclude(id=user_id)
device_owner_query = device_owner_query.exclude(id=user_id)

if facility_user_query.exists() or device_owner_query.exists():
raise serializers.ValidationError({
'username': _('An account with that username already exists')
})
return data

def create(self, validated_data):
user = self.Meta.model(**validated_data)
Expand Down
8 changes: 8 additions & 0 deletions kolibri/auth/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@ def test_user_update_password(self):
response = self.client.login(username=self.user.username, password=new_password, facility=self.facility)
self.assertTrue(response)

def test_user_update_password_non_partial_with_username(self):
new_password = 'baz'
self.client.patch(reverse('facilityuser-detail', kwargs={'pk': self.user.pk}),
{'password': new_password, 'username': self.user.username}, format="json")
self.client.logout()
response = self.client.login(username=self.user.username, password=new_password, facility=self.facility)
self.assertTrue(response)

def test_device_owner_update_info(self):
self.client.patch(reverse('deviceowner-detail', kwargs={'pk': self.device_owner.pk}), {'username': 'foo'}, format="json")
self.device_owner.refresh_from_db()
Expand Down
5 changes: 4 additions & 1 deletion kolibri/core/assets/src/api-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class Model {
payload[key] = attrs[key];
}
});
this.set(payload);
} else {
this.set(attrs);
payload = this.attributes;
Expand Down Expand Up @@ -431,7 +432,9 @@ export class Resource {
return JSON.stringify(
Object.assign(
{},
...Object.keys(allParams).sort().map(paramKey => ({ [paramKey]: allParams[paramKey] }))
...Object.keys(allParams)
.sort()
.map(paramKey => ({ [paramKey]: allParams[paramKey] }))
)
);
}
Expand Down
14 changes: 14 additions & 0 deletions kolibri/core/assets/test/api-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,20 @@ describe('Model', function() {
done();
});
});
it('should should call set once with the changed attributes', function(done) {
this.model.synced = true;
const payload = { somethingNew: 'new' };
const entity = {};
Object.assign(entity, this.model.attributes, payload);
this.response = { entity };
this.client = sinon.stub();
this.client.returns(Promise.resolve(this.response));
this.resource.client = this.client;
this.model.save(payload).then(() => {
assert.equal(this.model.attributes.somethingNew, 'new');
done();
});
});
});
describe('if called when Model.synced = false', function() {
describe('and the save is successful', function() {
Expand Down

0 comments on commit 4944d93

Please sign in to comment.