-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0bb0357
commit cec4da1
Showing
13 changed files
with
109 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +0,0 @@ | ||
# coding: utf-8 | ||
from django.apps import AppConfig | ||
|
||
|
||
class LoggerAppConfig(AppConfig): | ||
|
||
name = 'onadata.apps.logger' | ||
|
||
def ready(self): | ||
# Makes sure all signal handlers are connected | ||
from onadata.apps.logger import signals | ||
# Monkey patch reversion package to insert real user in DB instead of | ||
# system account superuser. | ||
from kobo_service_account.utils import reversion_monkey_patch | ||
reversion_monkey_patch() | ||
super().ready() | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# coding: utf-8 | ||
from django.apps import AppConfig | ||
|
||
|
||
class LoggerAppConfig(AppConfig): | ||
|
||
name = 'onadata.apps.logger' | ||
|
||
def ready(self): | ||
# Makes sure all signal handlers are connected | ||
from onadata.apps.logger import signals | ||
# Monkey patch reversion package to insert real user in DB instead of | ||
# system account superuser. | ||
from kobo_service_account.utils import reversion_monkey_patch | ||
reversion_monkey_patch() | ||
super().ready() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# coding: utf-8 | ||
from django.apps import AppConfig | ||
|
||
|
||
class MainConfig(AppConfig): | ||
name = 'onadata.apps.main' | ||
|
||
def ready(self): | ||
from onadata.apps.main import signals | ||
super().ready() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,27 @@ | ||
# coding: utf-8 | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
from guardian.shortcuts import assign_perm, get_perms_for_model | ||
from rest_framework.authtoken.models import Token | ||
|
||
from django.contrib.auth.models import User | ||
from onadata.apps.main.models.user_profile import UserProfile | ||
from onadata.libs.utils.user_auth import set_api_permissions_for_user | ||
|
||
|
||
@receiver(post_save, sender=User, dispatch_uid='set_api_permissions') | ||
def set_api_permissions(sender, instance=None, created=False, **kwargs): | ||
from onadata.libs.utils.user_auth import set_api_permissions_for_user | ||
if created: | ||
set_api_permissions_for_user(instance) | ||
|
||
|
||
@receiver(post_save, sender=User) | ||
def create_auth_token(sender, instance=None, created=False, **kwargs): | ||
if created: | ||
Token.objects.create(user=instance) | ||
|
||
|
||
@receiver(post_save, sender=UserProfile, dispatch_uid='set_object_permissions') | ||
def set_object_permissions(sender, instance=None, created=False, **kwargs): | ||
if created: | ||
for perm in get_perms_for_model(UserProfile): | ||
assign_perm(perm.codename, instance.user, instance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# coding: utf-8 | ||
from django.apps import AppConfig | ||
|
||
|
||
class ViewerConfig(AppConfig): | ||
name = 'onadata.apps.viewer' | ||
|
||
def ready(self): | ||
from onadata.apps.viewer import signals | ||
super().ready() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from django.conf import settings | ||
from django.core.files.storage import default_storage | ||
from django.db.models.signals import post_delete, post_save, pre_delete | ||
from django.dispatch import receiver | ||
from guardian.shortcuts import assign_perm, get_perms_for_model | ||
|
||
from onadata.apps.logger.models import XForm | ||
from onadata.apps.viewer.models.data_dictionary import DataDictionary | ||
from onadata.apps.viewer.models.export import Export | ||
from onadata.apps.viewer.models.parsed_instance import ParsedInstance | ||
|
||
|
||
@receiver(post_delete, sender=Export) | ||
def export_delete_callback(sender, **kwargs): | ||
export = kwargs['instance'] | ||
if export.filepath and default_storage.exists(export.filepath): | ||
default_storage.delete(export.filepath) | ||
|
||
|
||
@receiver(post_save, sender=DataDictionary, dispatch_uid='xform_object_permissions') | ||
def set_object_permissions(sender, instance=None, created=False, **kwargs): | ||
if created: | ||
for perm in get_perms_for_model(XForm): | ||
assign_perm(perm.codename, instance.user, instance) | ||
|
||
|
||
@receiver(pre_delete, sender=ParsedInstance) | ||
def remove_from_mongo(sender, **kwargs): | ||
instance_id = kwargs.get('instance').instance.id | ||
settings.MONGO_DB.instances.delete_one({'_id': instance_id}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters