Commit 43103ecb authored by Florent Chehab's avatar Florent Chehab

Bugs removed in backend

- comparaison when retreiving pending moderation wasn't done on the right elements
- Saving revision was done with user from request instead of updated by !
parent 3658285c
Pipeline #27306 passed with stages
in 2 minutes and 39 seconds
......@@ -19,7 +19,8 @@ CLEANED_MY_MODEL_DATA = {
def override_data(old_data, new_data):
for key in new_data:
old_data[key] = new_data[key]
if key in old_data:
old_data[key] = new_data[key]
return old_data
......@@ -110,6 +111,8 @@ class MyModelSerializer(MySerializerWithJSON):
if is_moderation_required(self.get_model_config()['moderation_level'], self.instance, self.user, self.user_level):
if self.instance is None: # we need to create the main model
# Store the user for squashing data in versions models
self.validated_data.updated_by = self.user
self.instance = super(
MyModelSerializer, self).save(*args, **kwargs)
......@@ -147,7 +150,15 @@ class MyModelSerializer(MySerializerWithJSON):
object_id=self.instance.pk,
)
self.clean_validated_data() # Make that it is done...
if pending_instance.new_object == self.validated_data:
# We have to compare the serialized data
# So we make sure to compare the same elements
key_to_remove = []
for key in self.initial_data:
if key not in self.validated_data:
key_to_remove.append(key)
for key in key_to_remove:
self.initial_data.pop(key, None)
if pending_instance.new_object == self.initial_data:
moderated_and_updated = False
self.validated_data['updated_by'] = pending_instance.updated_by
self.validated_data['updated_on'] = pending_instance.updated_on
......
......@@ -39,11 +39,9 @@ class MyModelVersionnedSerializer(MyModelSerializer):
return ContentType.objects.get_for_model(self.Meta.model).id
def save(self, *args, **kwargs):
user = self.context['request'].user
res = None
with reversion.create_revision():
res = self.my_save(*args, **kwargs)
reversion.set_user(user)
reversion.set_user(res.updated_by)
new_revision_saved.send(sender=self.__class__, obj=self.instance)
return res
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment