Пример #1
0
    def test_active_organization(self):
        request = self.mk_request('get', '/')
        request.user = AnonymousUser()
        self.assertIs(active_organization(request), None)

        user = self.mk_user()
        request.user = user
        self.assertIs(active_organization(request), None)

        organization = self.mk_organization()
        request.session[ORGANIZATION_SESSION_KEY] = organization.pk
        self.assertIs(active_organization(request), None)

        OrganizationUserRelation.objects.create(
            user=user, organization=organization)
        self.assertEqual(active_organization(request), organization)
Пример #2
0
 def get_context_data(self, *args, **kwargs):
     context = super(HomepageView, self).get_context_data(*args, **kwargs)
     active_org = active_organization(self.request)
     if active_org:
         context.update(
             {'is_admin': active_org.has_admin(self.request.user)})
     return context
Пример #3
0
 def get_context_data(self, *args, **kwargs):
     context = super(HomepageView, self).get_context_data(*args, **kwargs)
     active_org = active_organization(self.request)
     if active_org:
         context.update(
             {'is_admin': active_org.has_admin(self.request.user)})
     return context
Пример #4
0
    def test_active_organization(self):
        request = self.mk_request('get', '/')
        request.user = AnonymousUser()
        self.assertIs(active_organization(request), None)

        user = self.mk_user()
        request.user = user
        self.assertIs(active_organization(request), None)

        organization = self.mk_organization()
        request.session[ORGANIZATION_SESSION_KEY] = organization.pk
        self.assertIs(active_organization(request), None)

        OrganizationUserRelation.objects.create(user=user,
                                                organization=organization)
        self.assertEqual(active_organization(request), organization)
Пример #5
0
 def get_controllers_queryset(self, request):
     organization = active_organization(request)
     if organization is None:
         if request.user.is_superuser:
             return Controller.objects.all()
         return Controller.objects.none()
     return Controller.objects.filter(organization=organization)
Пример #6
0
 def get_controllers_queryset(self, request):
     organization = active_organization(request)
     if organization is None:
         if request.user.is_superuser:
             return Controller.objects.all()
         return Controller.objects.none()
     return Controller.objects.filter(organization=organization)
Пример #7
0
 def post(self, request):
     form = HiddenImportForm(request.POST)
     assert form.is_valid()
     controller = DockerController.from_marathon_app_data(
         self.request.user, active_organization(self.request),
         json.loads(form.cleaned_data['app_data']),
         form.cleaned_data['name'])
     tasks.start_new_controller.delay(controller.pk)
     messages.info(self.request, u"App created: {name}".format(
         **form.cleaned_data))
     return HttpResponseRedirect('/')
Пример #8
0
 def post(self, request):
     form = HiddenImportForm(request.POST)
     assert form.is_valid()
     controller = DockerController.from_marathon_app_data(
         self.request.user, active_organization(self.request),
         json.loads(form.cleaned_data['app_data']),
         form.cleaned_data['name'])
     tasks.start_new_controller.delay(controller.pk)
     messages.info(self.request,
                   u"App created: {name}".format(**form.cleaned_data))
     return HttpResponseRedirect('/')
Пример #9
0
    def form_valid(self, form):
        form.controller_form.instance.organization = active_organization(
            self.request)
        form.controller_form.instance.owner = self.request.user
        form.controller_form.instance.save()

        form.env_formset.instance = form.controller_form.instance
        form.link_formset.instance = form.controller_form.instance
        form.label_formset.instance = form.controller_form.instance

        response = super(ControllerCloneView, self).form_valid(form)
        tasks.start_new_controller.delay(form.controller_form.instance.id)
        return response
Пример #10
0
    def form_valid(self, form):
        form.controller_form.instance.organization = active_organization(
            self.request)
        form.controller_form.instance.owner = self.request.user
        form.controller_form.instance.save()

        form.env_formset.instance = form.controller_form.instance
        form.link_formset.instance = form.controller_form.instance
        form.label_formset.instance = form.controller_form.instance

        response = super(ControllerCloneView, self).form_valid(form)
        tasks.start_new_controller.delay(form.controller_form.instance.id)
        return response
Пример #11
0
def org(request):
    if not request.user.is_authenticated():
        return {
            'organizations': [],
            'active_organization': None,
            'is_active_organization_admin': False
        }

    active_org = active_organization(request)
    return {
        'organizations': Organization.objects.for_user(request.user),
        'active_organization': active_org,
        'is_active_organization_admin': (
            active_org and active_org.has_admin(request.user))
    }
Пример #12
0
def org(request):
    if not request.user.is_authenticated():
        return {
            'organizations': [],
            'active_organization': None,
            'is_active_organization_admin': False
        }

    active_org = active_organization(request)
    return {
        'organizations':
        Organization.objects.for_user(request.user),
        'active_organization':
        active_org,
        'is_active_organization_admin':
        (active_org and active_org.has_admin(request.user))
    }