Exemple #1
0
def shareadd(request):
    is_god = check_god(request)
    breadcrums = get_breadcrums(request)

    if request.method == 'POST':
        if not is_god:
            raise PermissionDenied

        form = ShareAddForm(request.POST)
        if not form.is_valid():
            return render_to_response('shareaddform.html',
                    locals(),
                    context_instance=RequestContext(request),
                    )

        new_share = form.save()

        request_apache_reload()
        return HttpResponseRedirect(reverse('sharemod', args=[str(new_share.id)]))

    form = ShareAddForm()
    return render_to_response('shareaddform.html',
            locals(),
            context_instance=RequestContext(request),
            )
Exemple #2
0
def projectadd(request):
    """
    Only Gods can add projects
    """
    is_god = check_god(request)
    breadcrums = get_breadcrums(request)

    if request.method == 'POST':
        if not is_god:
            raise PermissionDenied

        form = ProjectAddForm(request.POST)
        if not form.is_valid():
            return render_to_response('projectaddform.html',
                    locals(),
                    context_instance=RequestContext(request),
                    )

        new_project = form.save()

        request_apache_reload()
        return HttpResponseRedirect(reverse('projectmod', args=[str(new_project.id)]))

    # Handle GET requests
    form = ProjectAddForm()
    return render_to_response('projectaddform.html',
            locals(),
            context_instance=RequestContext(request),
            )
Exemple #3
0
def maintenance(request):

    if not os.path.isdir(settings.GENERATE_FOLDER):
        os.makedirs(settings.GENERATE_FOLDER)

    # writes configs, updates is_active flag

    def answer(message, error=None):
        return render_to_response("maintenance.html",
                {
                    'error': error,
                    'message': message,
                    'email_problem': email_problem,
                })


    email_problem = False
    disabled_members = []
    enabled_members = []

    # take care about expired users
    for m in Member.objects.filter(user__is_active=True, expires__lt=datetime.date.today()):
        print "The member", m.user, "expired at", m.expires, m.user.first_name, m.user.last_name, "will be set inactive"
        m.user.is_active = False
        m.user.save()
        request_apache_reload()
        disabled_members.append(m)
        mail_body = render_to_string("email/account_expired.txt", {'member': m})
        try:
            sent = send_mail("Account expired", mail_body, admins_emails[0], [admins_emails[0], m.user.email])
        except Exception, e:
            email_problem = True
Exemple #4
0
def projectmod(request, project_id):
    """
    Only project members can view and Gods may modify projects
    """

    project = get_object_or_404(Project,pk = project_id)
    is_god = check_god(request)
    member = Member.objects.get(user=request.user)
    breadcrums = get_breadcrums(request)

    if not (member in project.member_set.all() or is_god):
        raise PermissionDenied

    if request.method == "POST":
        if not is_god:
            raise PermissionDenied

        form = ProjectModForm(request.POST, instance=project, member=member) # remember database instance and inputs
        if not form.is_valid():
            return render_to_response("projectmodform.html",
                    locals(),
                    context_instance=RequestContext(request),
                    )

        new_members = [ int(m) for m in request.POST.getlist('members') ]
        members_project = Member.objects.in_bulk(new_members)
        for m in Member.objects.all():
            if m.pk in members_project.keys():
                m.projects.add(project)
            else:
                m.projects.remove(project)

        form.save() # Will also take care about m2m-relations

        # Renew form to ensure the new data can evaluated during ProjectModForm constructor
        # especially the 'allow_alumni' flag
        form = ProjectModForm(instance=project, member=member)

        request_apache_reload()
        success = True

        return render_to_response('projectmodform.html',
                locals(),
                context_instance=RequestContext(request),
                )

    # Handle GET requeset here
    form = ProjectModForm(instance=project, member=member)
    return render_to_response('projectmodform.html',
            locals(),
            context_instance=RequestContext(request),
            )
Exemple #5
0
def sharemod(request, share_id):

    share = Share.objects.get(pk = share_id)
    is_god = check_god(request)
    member = Member.objects.get(user=request.user)
    breadcrums = get_breadcrums(request)

    # determine if current user may view this share.
    # get all projects from member, after that all the related shares, after that the share's pks, afterthat set the query for these pks on Share
    shares = []
    for p in member.projects.all():
        for s in p.shares.all():
            shares.append(s.pk)

    if not (int(share_id) in shares or is_god):
        raise PermissionDenied

    if request.method == "POST":

        if not is_god:
            raise PermissionDenied

        form = ShareModForm(request.POST, instance=share) # remember database instance and inputs
        if not form.is_valid():
            return render_to_response('sharemodform.html',
                    locals(),
                    context_instance=RequestContext(request),
                    )

        form.save()
        request_apache_reload()
        success = True

        return render_to_response('sharemodform.html',
                locals(),
                context_instance=RequestContext(request),
                )

    # Handle GET request
    form = ShareModForm(instance=share)

    return render_to_response('sharemodform.html',
            locals(),
            context_instance=RequestContext(request),
            )
Exemple #6
0
        m.user.is_active = False
        m.user.save()
        request_apache_reload()
        disabled_members.append(m)
        mail_body = render_to_string("email/account_expired.txt", {'member': m})
        try:
            sent = send_mail("Account expired", mail_body, admins_emails[0], [admins_emails[0], m.user.email])
        except Exception, e:
            email_problem = True

    # take care about activating users
    for m in Member.objects.filter(user__is_active=False, expires__gte=datetime.date.today()):
        print "The member", m.user, "became active at", m.expires, m.user.first_name, m.user.last_name, "will be activated"
        m.user.is_active = True
        m.user.save()
        request_apache_reload()
        enabled_members.append(m)
        mail_body = render_to_string("email/account_activated.txt", {'member': m})
        try:
            sent = send_mail("Account activated", mail_body, admins_emails[0], [admins_emails[0], m.user.email])
        except Exception, e:
            email_problem = True

    # vcs and dav configs
    share_types = [s[0] for s in SHARE_TYPE_CHOICES]
    for typ in share_types:
        shares = get_shares_to_render(typ)
        for share in shares:
            filename = os.path.join(settings.GENERATE_FOLDER, typ + ".config")
            try:
                with open(filename, "wb") as apache_config_file: