예제 #1
0
 def put(self, request, *args, **kwargs):
     body = json.loads(request.body.decode('utf-8'))
     access = get_application_access_for_domain(self.domain)
     access.restrict = body['restrict']
     access.sqlappgroup_set.all().delete()
     access.sqlappgroup_set.set([
         SQLAppGroup(app_id=app_group['app_id'], group_id=app_group.get('group_id'))
         for app_group in body['app_groups']
     ], bulk=False)
     access.save()
     return json_response({'success': 1})
예제 #2
0
    def test_application_access(self):
        app1 = MockApplication(self.domain, "One")
        app2 = MockApplication(self.domain, "Two")
        app3 = MockApplication(self.domain, "Three")
        app4 = MockApplication(self.domain, "Four")

        o = get_application_access_for_domain(self.domain)
        o.sqlappgroup_set.set([
            SQLAppGroup(app_id=app1._id, group_id="321"),
            SQLAppGroup(app_id=app2._id, group_id="432"),
            SQLAppGroup(app_id=app3._id, group_id="543"),
        ],
                              bulk=False)
        o.save()

        refreshed = get_application_access_for_domain(self.domain)
        self.assertEqual(o.domain, refreshed.domain)
        self.assertEqual(3, refreshed.sqlappgroup_set.count())

        self.assertEqual(
            o.get_template_json([app1, app2, app4]), {
                "domain":
                self.domain,
                "restrict":
                False,
                "app_groups": [
                    {
                        "app_id": app4._id,
                        "group_id": None,
                    },
                    {
                        "app_id": app1._id,
                        "group_id": "321",
                    },
                    {
                        "app_id": app2._id,
                        "group_id": "432",
                    },
                ],
            })
예제 #3
0
 def update_or_create_sql_object(self, doc):
     model, created = self.sql_class().objects.update_or_create(
         domain=doc['domain'],
         defaults={
             "restrict": doc['restrict'],
         },
     )
     model.sqlappgroup_set.all().delete()
     model.sqlappgroup_set.set([
         SQLAppGroup(app_id=group['app_id'], group_id=group['group_id'])
         for group in doc['app_groups']
     ], bulk=False)
     return (model, created)