コード例 #1
0
ファイル: views.py プロジェクト: nejcjelovcan/Intranet
def commit_hook(request):
    """github post commit hook to log diaryies"""
    if request.META["REMOTE_ADDR"] not in ["207.97.227.253", "50.57.128.197"]:
        # see http://help.github.com/post-receive-hooks/
        return HttpResponseForbidden("Request not from github.")

    payload = simplejson.loads(request.POST["payload"])
    diaries = {}

    for commit in payload["commits"]:
        first_name, last_name = commit["author"]["name"].split()
        user = User.objects.get(
            models.Q(username=commit["author"]["email"])
            | (models.Q(first_name=first_name) & models.Q(last_name=last_name))
        )
        commits = diaries.get(user, [])
        commits.append("Commit: %(message)s\n %(url)s" % commit)
        diaries[user] = commits

    for user, text in diaries.iteritems():
        # TODO: if there is a diary for intranet for today, append to that
        diary = Diary(
            log_formal="\n".join(text), author=user, length=datetime.time(1), task=Project.objects.get(id=2)  # 1h
        )
        diary.save()
    return HttpResponse("OK")
コード例 #2
0
ファイル: views.py プロジェクト: avian2/kiberpipa-intranet
def commit_hook(request):
    """github post commit hook to log diaryies"""
    if request.META['REMOTE_ADDR'] not in ['207.97.227.253', '50.57.128.197']:
        # see http://help.github.com/post-receive-hooks/
        return HttpResponseForbidden('Request not from github.')

    payload = simplejson.loads(request.POST['payload'])
    diaries = {}

    for commit in payload['commits']:
        first_name, last_name = commit['author']['name'].split()
        user = User.objects.get(models.Q(username=commit['author']['email']) | (models.Q(first_name=first_name) & models.Q(last_name=last_name)))
        commits = diaries.get(user, [])
        commits.append("Commit: %(message)s\n %(url)s" % commit)
        diaries[user] = commits

    for user, text in diaries.iteritems():
        # TODO: if there is a diary for intranet for today, append to that
        diary = Diary(
            log_formal='\n'.join(text),
            author=user,
            length=datetime.time(1),  # 1h
            task=Project.objects.get(id=2),
        )
        diary.save()
    return HttpResponse('OK')
コード例 #3
0
ファイル: views.py プロジェクト: avian2/kiberpipa-intranet
def dezurni_add(request):
    new_data = request.POST.copy()
    if not request.POST or not 'uniqueSpot' in new_data:
        return HttpResponseRedirect('../')

    datum = datetime.strptime(str(request.POST['uniqueSpot']), "%d.%m.%y-%H:%M")

    p = Diary(date=datum,
              author=request.user,
              task=Project.objects.get(pk=22),
              log_formal=request.POST['log_formal'],
              log_informal=request.POST['log_informal'],)
    p.save()
    return HttpResponseRedirect('../')
コード例 #4
0
ファイル: views.py プロジェクト: gandalfar/Intranet
def tehniki_add(request):
    id = request.POST['uniqueSpot']
    if not id:
        return HttpResponseRedirect('../')

    event = Event.objects.get(pk=id)

    p = Diary(
        date=event.start_date,
        event=event,
        author=request.user,
        task=Project.objects.get(pk=23),
        log_formal=request.POST['log_formal'],
        log_informal=request.POST['log_informal'],
        length=datetime.time(int(request.POST.get('length', 1)), 0),
    )
    p.save()

    return HttpResponseRedirect('../')
コード例 #5
0
ファイル: views.py プロジェクト: nejcjelovcan/Intranet
def dezurni_add(request):
    new_data = request.POST.copy()
    if not request.POST or not "uniqueSpot" in new_data:
        return HttpResponseRedirect("../")

    d = mx.DateTime.DateTimeFrom(request.POST["uniqueSpot"].__str__())
    datum = datetime.datetime(
        year=d.year, month=d.month, day=d.day, hour=d.hour, minute=d.minute, second=0, microsecond=0
    )

    p = Diary(
        date=datum,
        author=request.user,
        task=Project.objects.get(pk=22),
        log_formal=request.POST["log_formal"],
        log_informal=request.POST["log_informal"],
    )
    p.save()
    return HttpResponseRedirect("../")
コード例 #6
0
ファイル: views.py プロジェクト: avian2/kiberpipa-intranet
def add_member(request):
    """Add kiberpipa memeber with all the stuff"""
    if not request.user.is_staff:
        return

    form = NewMemberForm(request.POST or None)

    if request.method == "POST" and form.is_valid():
        # create ldap record
        password = ''.join(random.sample(string.letters + string.digits, 8))
        password_hash = ldap_salted_sha1.encrypt(password)

        ldif_template = get_template('org/member_add.ldif').render(Context(dict(
            data=form.cleaned_data,
            password_hash=password_hash,
        )))

        with tempfile.NamedTemporaryFile() as f:
            f.write(ldif_template.encode('utf-8'))
            f.flush()
            
            p = subprocess.Popen('sudo -u root ldapadd -D cn=admin,dc=kiberpipa,dc=org -f %s -w %s' % (f.name, settings.LDAP_PASSWORD),
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
                                 shell=True)
            
            stdout, stderr = p.communicate()
            if p.returncode != 0:
                raise Exception("Failed adding a member to opendalp.")

        # add him to pipa-org
        if form.cleaned_data['add_to_private_mailinglist']:
            mailman_list = List.objects.get(id=2)
            try:
                mailman_list.subscribe(form.cleaned_data['email'])
            except:
                pass  # member is already subscribed

        # send email to new user
        html = get_template('mail/member_add_welcome_email.html').render(
            Context(dict(
                username=form.cleaned_data['username'],
                password=password,
        )))
        send_mail(u'Dobrodošel/a v Kiberpipi!',
                  html,
                  settings.DEFAULT_FROM_EMAIL,
                  [form.cleaned_data['email']])

        # add a diary we added a member
        diary = Diary(
            log_formal=u"Dodal novega člana: %s (%s %s)" % (form.cleaned_data['username'],
                                                            form.cleaned_data['firstname'],
                                                            form.cleaned_data['surname']),
            author=request.user,
            length=datetime.time(1),  # 1h
            task=Project.objects.get(id=2),
        )
        diary.save()

        return render_to_response(
            'org/member_add_success.html',
            {'email': form.cleaned_data['email']},
            context_instance=RequestContext(request))

    return render_to_response(
        'org/member_add.html',
        {'form': form},
        context_instance=RequestContext(request))
コード例 #7
0
ファイル: ci_to_diary.py プロジェクト: gandalfar/Intranet
#!/usr/bin/env python

#called as post-commit script for intranet ci
import sys

from intranet.org.models import Project, Diary

from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.conf import settings

current_page = Site.objects.get(id=settings.SITE_ID)

user = User.objects.get(username=sys.argv[1])
intranet = Project.objects.get(id=2)
log_formal = sys.argv[2]
log_formal += '\nchangeset: https://%s/projekti/intranet/changeset/%s/\n' % (current_page.domain, sys.argv[3])
diary = Diary(log_formal=log_formal, author=user, length='00:00:00', task=intranet)
diary.save()
コード例 #8
0
ファイル: views.py プロジェクト: nejcjelovcan/Intranet
def add_member(request):
    """Add kiberpipa memeber with all the stuff"""
    if not request.user.is_staff:
        return

    form = NewMemberForm(request.POST or None)

    if request.method == "POST" and form.is_valid():
        # create ldap record
        password = "".join(random.sample(string.letters + string.digits, 8))
        password_hash = ldap_salted_sha1.encrypt(password)

        uid = int(
            subprocess.Popen(
                "getent passwd | awk -F: '$3 < 3000 { print $3 }' | sort -n | tail -1",
                stdout=subprocess.PIPE,
                shell=True,
            )
            .communicate()[0]
            .strip()
        )
        uid += 1
        gid = int(
            subprocess.Popen(
                "getent group | awk -F: '$3 < 3000 { print $3 }' | sort -n | tail -1",
                stdout=subprocess.PIPE,
                shell=True,
            )
            .communicate()[0]
            .strip()
        )
        gid += 1

        ldif_template = get_template("org/member_add.ldif").render(
            Context(dict(data=form.cleaned_data, password_hash=password_hash, uid=uid, gid=gid))
        )

        with tempfile.NamedTemporaryFile() as f:
            f.write(ldif_template.encode("utf-8"))
            f.flush()
            subprocess.check_call(
                "sudo -u root ldapadd -D cn=admin,dc=kiberpipa,dc=org -f %s -w %s" % (f.name, settings.LDAP_PASSWORD),
                shell=True,
            )

        # create home folder
        # TODO: dogbert login
        # subprocess.check_call('sudo -u root mkdir -p /home/%s' % form.cleaned_data['username'],
        #                      shell=True)
        # TODO: chown it (sudoers should be very strict about this)
        # subprocess.check_call('sudo -u root chown -p /home/%s' % form.cleaned_data['username'],
        #                      shell=True)

        # TODO: add member to redmine group

        # add him to pipa-org
        if form.cleaned_data["add_to_private_mailinglist"]:
            mailman_list = List.objects.get(id=2)
            try:
                mailman_list.subscribe(form.cleaned_data["email"])
            except:
                pass  # member is already subscribed

        # send email to new user
        html = get_template("mail/member_add_welcome_email.html").render(
            Context(dict(username=form.cleaned_data["username"], password=password))
        )
        send_mail(u"Dobrodošel/a v Kiberpipi!", html, settings.DEFAULT_FROM_EMAIL, [form.cleaned_data["email"]])

        # add a diary we added a member
        diary = Diary(
            log_formal=u"Dodal novega člana: %s (%s %s)"
            % (form.cleaned_data["username"], form.cleaned_data["firstname"], form.cleaned_data["surname"]),
            author=request.user,
            length=datetime.time(1),  # 1h
            task=Project.objects.get(id=2),
        )
        diary.save()

        return render_to_response(
            "org/member_add_success.html",
            {"email": form.cleaned_data["email"]},
            context_instance=RequestContext(request),
        )

    return render_to_response("org/member_add.html", {"form": form}, context_instance=RequestContext(request))