예제 #1
0
    def handle(self, *args, **options):
        if not len(args):
            user = User.objects(username='******').first() or User(
                username='******').save()
            user.group = Group.objects(name='Administrator').first()
            user.set_password('password')
            location = Location.objects(type='district').first() or Location(
                name='Kampala', type='district').save()
            profile = UserProfile.objects(phone='N/A').first() or UserProfile(
                phone='N/A',
                name='Admin',
                location=location,
                email='*****@*****.**').save()
            profile.user = user
            profile.save()
        else:
            user = User.objects(username=args[0]).first() or User(
                username=args[0]).save()
            user.group = Group.objects(name='Administrator').first()
            user.set_password(args[1])
            location = Location.objects(name=args[4]).first() or Location(
                name=args[4], type='district').save()
            profile = UserProfile.objects(
                phone=args[5]).first() or UserProfile(
                    phone=args[5],
                    name=args[3],
                    location=location,
                    email=args[2]).save().save()
            profile.user = user
            profile.save()

        self.stdout.write('Successfully created superuser')
예제 #2
0
 def test_does_not_have_group_permissions(self):
     ct = ContentType(app_label='dms', model='test', name='test').save()
     permission = Permission(name='can test things', codename='can_test_things', content_type=ct.id).save()
     group = Group(name='Test Group', permissions=[permission]).save()
     user = User(username='******', password='******', group=group)
     self.assertFalse(user.has_perm('dmx.can_test_things'))
     self.assertFalse(user.has_perm('dms.cant_test_things'))
예제 #3
0
 def login_user(self):
     user = User.objects.create(username='******',
                                email='*****@*****.**')
     user.group = Group.objects(name='Administrator').first()
     user.set_password('password')
     self.client.login(username='******', password='******')
     return user
    def test_serializing_group_name(self):
        mobile_user_attr = self.mobile_user.copy()
        group = Group.objects().first()
        mobile_user_attr['user'] = User(username='******', password='******', group=group).save()
        mobile_user = UserProfile(**mobile_user_attr).save()

        serialized_object = UserProfileSerializer(mobile_user)
        self.assertEqual(str(group.id), serialized_object.data['group'])
예제 #5
0
 def login_user_with_group(self, grp):
     group = Group.objects(name=grp.name).first()
     user = User.objects.create(username='******',
                                email='*****@*****.**',
                                group=group)
     user.set_password('password')
     self.client.login(username='******', password='******')
     return user
예제 #6
0
    def test_should_get_user_permissions(self):
        ct = ContentType(app_label='dms', model=str(uuid.uuid4()), name=str(uuid.uuid4())).save()
        manage_users = Permission(name='can manage users', codename='can_manage_users', content_type=ct.id).save()
        manage_polls = Permission(name='can manage users', codename='can_manage_polls', content_type=ct.id).save()
        group = Group(name='UserGroup', permissions=[manage_users, manage_polls]).save()
        user = User(username="******", email="*****@*****.**", group=group)
        user.set_password("some-password")

        self.assertEqual(['can_manage_users', 'can_manage_polls'], user.get_permissions())
예제 #7
0
    def test_should_serialize_groups_object(self):
        serialized_group = dict(name='Test Group')
        group_object = Group(name='Test Group',
                             permissions=[self.permission]).save()

        serialized_object = GroupSerializer(group_object)
        self.assertDictContainsSubset(serialized_group, serialized_object.data)
        self.assertIsNotNone(serialized_object.data.get('id'))
        self.assertIsNone(serialized_object.data.get('permission'))
    def test_reset_password_saves_new_password(self, mock_send_email):
        district = Location(**dict(name='Kampala', parent=None, type='district'))
        district.save()
        profile = UserProfile(name='Andrew', email='*****@*****.**', location=district, phone='2570760540326')
        user = UserProfileService(profile).setup_new_user('andrew', str((Group.objects().first()).id))
        old_password = user.password
        profile.user = user

        UserProfileService(profile).reset_password()
        self.assertNotEqual(old_password, profile.user.password)
 def test_new_password_is_sent_in_email(self, mock_send_mail, mock_make_password):
     message = "Andrew http://necoc.org.ug andrew blabla"
     mock_make_password.return_value = 'blabla'
     profile = UserProfile(name='Andrew', email='*****@*****.**')
     group = Group.objects().first()
     UserProfileService(profile).setup_new_user('andrew', str(group.id))
     mock_send_mail.assert_called_with('Your NECOC Account',
                                       message,
                                       settings.DEFAULT_FROM_EMAIL,
                                       ['*****@*****.**'])
    def test_post_with_group_associates_user_to_group(self):
        attr = self.mobile_user_to_post.copy()
        attr['username'] = '******'
        group = Group.objects().first()
        attr['group'] = str(group.id)
        response = self.client.post(self.API_ENDPOINT, data=attr)
        self.assertEqual(201, response.status_code)

        retrieved_user = User.objects(username='******').first()
        self.assertEqual(group, retrieved_user.group)
    def test_post_with_group_associates_user_to_group(self):
        attr = self.mobile_user_to_post.copy()
        attr['username'] = '******'
        group = Group.objects().first()
        attr['group'] = str(group.id)
        response = self.client.post(self.API_ENDPOINT, data=attr)
        self.assertEqual(201, response.status_code)

        retrieved_user = User.objects(username='******').first()
        self.assertEqual(group, retrieved_user.group)
예제 #12
0
    def handle(self, *args, **options):
        if not len(args):
            user = User.objects(username='******').first() or User(username='******').save()
            user.group = Group.objects(name='Administrator').first()
            user.set_password('password')
            location = Location.objects(type='district').first() or Location(name='Kampala', type='district').save()
            profile = UserProfile.objects(phone='N/A').first() or UserProfile(phone='N/A', name='Admin', location=location, email='*****@*****.**').save()
            profile.user = user
            profile.save()
        else:
            user = User.objects(username=args[0]).first() or User(username=args[0]).save()
            user.group = Group.objects(name='Administrator').first()
            user.set_password(args[1])
            location = Location.objects(name=args[4]).first() or Location(name=args[4], type='district').save()
            profile = UserProfile.objects(phone=args[5]).first() or UserProfile(phone=args[5], name=args[3], location=location, email=args[2]).save().save()
            profile.user = user
            profile.save()

        self.stdout.write('Successfully created superuser')
예제 #13
0
    def test_serializing_group_name(self):
        mobile_user_attr = self.mobile_user.copy()
        group = Group.objects().first()
        mobile_user_attr['user'] = User(username='******',
                                        password='******',
                                        group=group).save()
        mobile_user = UserProfile(**mobile_user_attr).save()

        serialized_object = UserProfileSerializer(mobile_user)
        self.assertEqual(str(group.id), serialized_object.data['group'])
예제 #14
0
    def handle(self, *args, **options):
        if len(args):
            user = User.objects(username=args[0], email=args[2]).first() or User(username=args[0], email=args[2])
            if len(args) > 3:
                ct = ContentType(app_label='dms', model=str(uuid.uuid4()), name=str(uuid.uuid4())).save()
                permission = Permission(name=args[3], codename=args[3], content_type=ct.id).save()
                group = Group(name=str(uuid.uuid4()), permissions=[permission]).save()
                user.group = group

            user.set_password(args[1])

            self.stdout.write('Successfully created user')
예제 #15
0
 def login_with_permission(self, permission_codename):
     self.client.logout()
     ct = ContentType(app_label='dms',
                      model=str(uuid.uuid4()),
                      name=str(uuid.uuid4())).save()
     permission = Permission(name=permission_codename,
                             codename=permission_codename,
                             content_type=ct.id).save()
     group = Group(name=str(uuid.uuid4()), permissions=[permission]).save()
     user = User(username='******', group=group)
     user.set_password('pw')
     self.client.login(username='******', password='******')
    def test_update_with_group_associates_user_to_new_group(self):
        attr = self.mobile_user_to_post.copy()
        attr['username'] = '******'
        group = Group.objects().first()
        attr['group'] = str(group.id)
        self.client.post(self.API_ENDPOINT, data=attr)

        retrieved_user = User.objects(username='******').first()
        retrieved_user_profile = UserProfile.objects(user=retrieved_user).first()
        new_group = Group.objects().all()[2]

        new_attr = self.mobile_user_to_post.copy()
        new_attr['username'] = '******'
        new_attr['location'] = str(new_attr['location'])
        new_attr['group'] = str(new_group.id)
        new_attr['id'] = str(retrieved_user_profile.id)

        url = self.API_ENDPOINT + str(retrieved_user_profile.id) + '/'
        response = self.client.post(url,
                                    data=new_attr)
        self.assertEqual(200, response.status_code)
        retrieved_user = User.objects(username='******').first()
        self.assertEqual(new_group, retrieved_user.group)
    def test_update_with_group_associates_user_to_new_group(self):
        attr = self.mobile_user_to_post.copy()
        attr['username'] = '******'
        group = Group.objects().first()
        attr['group'] = str(group.id)
        self.client.post(self.API_ENDPOINT, data=attr)

        retrieved_user = User.objects(username='******').first()
        retrieved_user_profile = UserProfile.objects(
            user=retrieved_user).first()
        new_group = Group.objects().all()[2]

        new_attr = self.mobile_user_to_post.copy()
        new_attr['username'] = '******'
        new_attr['location'] = str(new_attr['location'])
        new_attr['group'] = str(new_group.id)
        new_attr['id'] = str(retrieved_user_profile.id)

        url = self.API_ENDPOINT + str(retrieved_user_profile.id) + '/'
        response = self.client.post(url, data=new_attr)
        self.assertEqual(200, response.status_code)
        retrieved_user = User.objects(username='******').first()
        self.assertEqual(new_group, retrieved_user.group)
    def test_password_reset_sends_email(self, mock_send_mail, mock_make_password):
        message = "Andrew blabla http://necoc.org.ug [email protected]"
        mock_make_password.return_value = 'blabla'
        district = Location(**dict(name='Kampala', parent=None, type='district'))
        district.save()
        profile = UserProfile(name='Andrew', email='*****@*****.**', location=district, phone='2570760540326')
        user = UserProfileService(profile).setup_new_user('andrew', str((Group.objects().first()).id))
        profile.user = user

        UserProfileService(profile).reset_password()
        mock_send_mail.assert_any_call('NECOC Password Reset',
                                       message,
                                       "*****@*****.**",
                                       ['*****@*****.**'])
예제 #19
0
    def process(self):
        """ Function in charge to import Vulture Groups into database

        :return:
        """
        group_names = (
            'application_manager',
            'administrator',
            'security_manager',
            'system_manager',
            'guest',
        )
        for group in group_names:
            try:
                Group.objects.get(name=group)
            except Group.DoesNotExist as e:
                Group(name=group).save()
        print("Vulture groups successfully imported")
 def test_associates_group_to_user(self, mock_send_mail, mock_make_password):
     mock_make_password.return_value = 'blabla'
     profile = UserProfile(name='Andrew', email='*****@*****.**')
     group = Group.objects().first()
     user = UserProfileService(profile).setup_new_user('andrew', str(group.id))
     self.assertEqual(group, user.group)
 def test_setup_new_user_saves_new_password(self, mock_send_mail):
     profile = UserProfile(name='Andrew', email='*****@*****.**')
     group = Group.objects().first()
     user = UserProfileService(profile).setup_new_user('andrew', str(group.id))
     self.assertIsNotNone(user.password)
예제 #22
0
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}

# Heroku Config
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')


mongoengine.connect(MONGODB_NAME, host = MONGODB_CONNECTION_STRING)

try:
    from mongoengine.django.auth import Group
    
    group_count = Group.objects.count()
    if group_count == 0:
        group_users = Group(name = 'users')
        group_users.save()
        group_ombudsman = Group(name = 'ombudsman')
        group_ombudsman.save()
except Exception, e: 
    print str(e)
예제 #23
0
파일: base.py 프로젝트: unicefuganda/necoc
 def login_user_with_group(self, grp):
     group = Group.objects(name=grp.name).first()
     user = User.objects.create(username='******', email='*****@*****.**', group=group)
     user.set_password('password')
     self.client.login(username='******', password='******')
     return user
예제 #24
0
파일: base.py 프로젝트: unicefuganda/necoc
 def login_user(self):
     user = User.objects.create(username='******', email='*****@*****.**')
     user.group = Group.objects(name='Administrator').first()
     user.set_password('password')
     self.client.login(username='******', password='******')
     return user
예제 #25
0
 def post_save(self, obj, created=False):
     group_id = self.request.DATA.get('group', None)
     if(group_id):
         obj.user.group = Group.objects(id=group_id).first()
         obj.user.save()
     self.replace_image(obj)
예제 #26
0
 def list(self, request, *args, **kwargs):
     queryset = Group.objects()
     data = [GroupSerializer(query).data for query in queryset]
     return Response(data)
예제 #27
0
 def list(self, request, *args, **kwargs):
     queryset = Group.objects()
     data = [GroupSerializer(query).data for query in queryset]
     return Response(data)
예제 #28
0
 def in_groups(u):
     if u.is_authenticated():
         groups = Group.objects(name__in=group_names)
         if bool(u.is_member_of(groups)) | u.is_superuser:
             return True
     return False
예제 #29
0
 def login_without_permissions(self):
     self.client.logout()
     empty_group = Group(name='Empty', permissions=[])
     User(username='******', password='******', group=empty_group)
     self.client.login(username='******', password='******')
예제 #30
0
    def handle(self, *args, **options):
        try:
            # ct, created = ContentType.objects.get_or_create(app_label='dms', model='', name='')
            ct = ContentType(app_label='dms', model='', name='').save()
            manage_users = Permission(name='can manage users',
                                      codename='can_manage_users',
                                      content_type=ct.id).save()
            manage_polls = Permission(name='can manage polls',
                                      codename='can_manage_polls',
                                      content_type=ct.id).save()
            view_polls = Permission(name='can view polls',
                                    codename='can_view_polls',
                                    content_type=ct.id).save()
            view_messages = Permission(name='can view messages',
                                       codename='can_view_messages',
                                       content_type=ct.id).save()
            view_disasters = Permission(name='can view disasters',
                                        codename='can_view_disasters',
                                        content_type=ct.id).save()
            manage_disasters = Permission(name='can manage disasters',
                                          codename='can_manage_disasters',
                                          content_type=ct.id).save()
            manage_messages = Permission(name='can manage messages',
                                         codename='can_manage_messages',
                                         content_type=ct.id).save()
            manage_settings = Permission(name='can manage settings',
                                         codename='can_manage_settings',
                                         content_type=ct.id).save()

            Group(name='Administrator',
                  permissions=[
                      manage_users,
                      manage_polls,
                      view_polls,
                      view_disasters,
                      manage_disasters,
                      manage_messages,
                      manage_settings,
                  ]).save()

            Group(name='IT Assistant',
                  permissions=[
                      view_polls, view_disasters, view_disasters,
                      manage_disasters, manage_messages
                  ]).save()

            Group(name='Disaster Preparedness Officer',
                  permissions=[
                      manage_polls, view_polls, view_disasters,
                      manage_disasters, manage_messages
                  ]).save()

            Group(name='Disaster Management Officer',
                  permissions=[
                      manage_polls, view_polls, view_disasters,
                      manage_disasters, manage_messages
                  ]).save()

            Group(name='Management Team',
                  permissions=[
                      manage_users, manage_polls, view_polls, view_disasters,
                      manage_disasters, manage_messages
                  ]).save()

            Group(name='DDMC Chairperson',
                  permissions=[view_polls, view_messages,
                               view_disasters]).save()

            Group(name='CAO',
                  permissions=[view_polls, view_messages,
                               view_disasters]).save()

            Group(name='DDMC',
                  permissions=[
                      view_polls, view_messages, manage_disasters,
                      view_disasters
                  ]).save()
        except:
            print "You have likely created the user group data already"