def _login_user_and_profile(self, extra_post_data={}): post_data = { 'username': '******', 'email': '*****@*****.**', 'password1': 'bobbob', 'password2': 'bobbob', 'name': 'Bob', 'city': 'Bobville', 'country': 'US', 'organization': 'Bob Inc.', 'home_page': 'bob.com', 'twitter': 'boberama' } url = '/accounts/register/' post_data = dict(post_data.items() + extra_post_data.items()) self.response = self.client.post(url, post_data) try: self.user = User.objects.get(username=post_data['username']) except User.DoesNotExist: pass else: self.user.is_active = True self.user.save() self.assertTrue( self.client.login(username=self.user.username, password='******')) self.extra = { 'HTTP_AUTHORIZATION': 'Token %s' % self.user.auth_token} set_api_permissions_for_user(self.user)
def handle(self, *args, **options): # XForms for xform in queryset_iterator(XForm.objects.all()): OwnerRole.add(xform.user, xform) # UserProfile for profile in queryset_iterator(UserProfile.objects.all()): set_api_permissions_for_user(profile.user) OwnerRole.add(profile.user, profile) if profile.created_by is not None: OwnerRole.add(profile.created_by, profile) # OrganizationProfile for profile in queryset_iterator(OrganizationProfile.objects.all()): OwnerRole.add(profile.user, profile) if profile.created_by is not None: OwnerRole.add(profile.created_by, profile) if profile.creator is not None: OwnerRole.add(profile.creator, profile) # Project for project in queryset_iterator(Project.objects.all()): OwnerRole.add(project.organization, project) OwnerRole.add(project.created_by, project)
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)