예제 #1
0
def remove_supporter(site_id, crsid):
    from sitesmanagement.models import Site
    site = Site.objects.get(id=site_id)
    user = User.objects.get(username=crsid)
    site.supporters.remove(user)
    from apimws.ansible import launch_ansible_site
    launch_ansible_site(site)
예제 #2
0
 def form_valid(self, form):
     form.user = self.request.user
     super(SiteEditEmail, self).form_valid(form)
     if 'email' in form.changed_data and self.object.email:
         email_confirmation(self.object)
         launch_ansible_site(self.object)
     return redirect(self.object)
예제 #3
0
def force_update(request, site_id):
    site = privileges_check(site_id, request.user)

    if site is None:
        return HttpResponseForbidden()

    if request.method == 'POST':
        launch_ansible_site(site)  # to refresh lookup lists
        # TODO add message to the user

    return redirect(site)
예제 #4
0
def add_supporter(request, site_id):
    site = privileges_check(site_id, request.user)

    if site is None:
        return HttpResponseForbidden()

    if request.method == 'POST':
        site.supporters.add(request.user)
        launch_ansible_site(site)
        remove_supporter.apply_async(args=(site.id, request.user.username),
                                     countdown=3600)  # Remove supporter after 1 hour

    return redirect(site)
예제 #5
0
def auth_change(request, site_id):
    site = privileges_check(site_id, request.user)

    if site is None:
        return HttpResponseForbidden()

    if not site.production_service or site.production_service.virtual_machines.count() == 0 \
            or site.production_service.is_busy:
        return redirect(site)

    if request.method == 'POST':
        authuserlist = validate_crsid_list(
            request.POST.getlist('users_crsids'))
        sshuserlist = validate_crsid_list(
            request.POST.getlist('sshusers_crsids'))
        authgrouplist = validate_groupid_list(request.POST.getlist('groupids'))
        sshauthgrouplist = validate_groupid_list(
            request.POST.getlist('sshgroupids'))
        site.users.clear()
        site.users.add(*authuserlist)
        site.ssh_users.clear()
        site.ssh_users.add(*sshuserlist)
        site.groups.clear()
        site.groups.add(*authgrouplist)
        site.ssh_groups.clear()
        site.ssh_groups.add(*sshauthgrouplist)
        launch_ansible_site(
            site
        )  # to add or delete users from the ssh/login auth list of the server
        return redirect(site)

    breadcrumbs = {
        0:
        dict(name='Managed Web Server: ' + str(site.name),
             url=site.get_absolute_url()),
        1:
        dict(name='Authorisation',
             url=reverse(auth_change, kwargs={'site_id': site.id}))
    }

    return render(
        request, 'mws/auth.html', {
            'authorised_users': site.users.all(),
            'sshuserlist': site.ssh_users.all(),
            'authorised_groups': site.groups.all(),
            'sshusers_groups': site.ssh_groups.all(),
            'breadcrumbs': breadcrumbs,
            'sidebar_messages': warning_messages(site),
            'site': site
        })