|
1 | 1 | from django.apps import apps |
2 | 2 | from django.utils import timezone |
3 | 3 | from django.conf import settings |
4 | | -from django.db import models |
| 4 | +from django.db import models, transaction |
5 | 5 |
|
6 | 6 | from osf.utils.fields import NonNaiveDateTimeField |
7 | 7 |
|
@@ -951,31 +951,32 @@ def _on_complete(self, event_data): |
951 | 951 | if registration.is_spammy: |
952 | 952 | raise NodeStateError('Cannot approve a spammy registration') |
953 | 953 |
|
954 | | - super()._on_complete(event_data) |
955 | | - self.save() |
956 | | - registered_from = registration.registered_from |
957 | | - # Pass auth=None because the registration initiator may not be |
958 | | - # an admin on components (component admins had the opportunity |
959 | | - # to disapprove the registration by this point) |
960 | | - registration.set_privacy('public', auth=None, log=False) |
961 | | - for child in registration.get_descendants_recursive(primary_only=True): |
962 | | - child.set_privacy('public', auth=None, log=False) |
963 | | - # Accounts for system actions where no `User` performs the final approval |
964 | | - auth = Auth(user) if user else None |
965 | | - registered_from.add_log( |
966 | | - action=NodeLog.REGISTRATION_APPROVAL_APPROVED, |
967 | | - params={ |
968 | | - 'node': registered_from._id, |
969 | | - 'registration': registration._id, |
970 | | - 'registration_approval_id': self._id, |
971 | | - }, |
972 | | - auth=auth, |
973 | | - ) |
974 | | - for node in registration.root.node_and_primary_descendants(): |
975 | | - self._add_success_logs(node, user) |
976 | | - node.update_search() # update search if public |
| 954 | + with transaction.atomic(): |
| 955 | + super()._on_complete(event_data) |
| 956 | + self.save() |
| 957 | + registered_from = registration.registered_from |
| 958 | + # Pass auth=None because the registration initiator may not be |
| 959 | + # an admin on components (component admins had the opportunity |
| 960 | + # to disapprove the registration by this point) |
| 961 | + registration.set_privacy('public', auth=None, log=False) |
| 962 | + for child in registration.get_descendants_recursive(primary_only=True): |
| 963 | + child.set_privacy('public', auth=None, log=False) |
| 964 | + # Accounts for system actions where no `User` performs the final approval |
| 965 | + auth = Auth(user) if user else None |
| 966 | + registered_from.add_log( |
| 967 | + action=NodeLog.REGISTRATION_APPROVAL_APPROVED, |
| 968 | + params={ |
| 969 | + 'node': registered_from._id, |
| 970 | + 'registration': registration._id, |
| 971 | + 'registration_approval_id': self._id, |
| 972 | + }, |
| 973 | + auth=auth, |
| 974 | + ) |
| 975 | + for node in registration.root.node_and_primary_descendants(): |
| 976 | + self._add_success_logs(node, user) |
| 977 | + node.update_search() # update search if public |
977 | 978 |
|
978 | | - self.save() |
| 979 | + self.save() |
979 | 980 |
|
980 | 981 | def _on_reject(self, event_data): |
981 | 982 | user = event_data.kwargs.get('user') |
|
0 commit comments