Esempio n. 1
0
    def post(self, completed, planned, tags, isedit=False, **kwargs):
        loginid = cherrypy.request.loginid

        assert cherrypy.request.method.upper() == 'POST'

        cur = model.get_cursor()

        cur.execute(
            '''SELECT IFNULL(email, userid)
                       FROM users
                       WHERE userid = ?''', (loginid, ))
        email, = cur.fetchone()

        completed = completed or None
        planned = planned or None
        tags = tags or None

        today = util.today().toordinal()
        now = util.now()
        bugs = kwargs_to_buglist(kwargs)

        if isedit:
            cur.execute(
                '''UPDATE posts
                           SET completed = ?, planned = ?, tags = ?, posttime = ?
                           WHERE userid = ?
                             AND postdate = (
                               SELECT lastpostdate FROM (
                                 SELECT MAX(postdate) AS lastpostdate
                                 FROM posts AS p2
                                 WHERE p2.userid = ?
                               ) AS maxq
                             )''',
                (completed, planned, tags, now, loginid, loginid))
        else:
            cur.execute(
                '''INSERT INTO posts
                           (userid, postdate, posttime, completed, planned, tags)
                           VALUES (?, ?, ?, ?, ?, ?)''',
                (loginid, today, now, completed, planned, tags))

        for bug in bugs:
            model.save_bugstatus(cur, loginid, bug, today)
        allteam, sendnow = model.get_userteam_emails(loginid)
        if isinstance(completed, str):
            completed = completed.decode("utf-8")
        if isinstance(planned, str):
            planned = planned.decode("utf-8")
        if isinstance(tags, str):
            tags = tags.decode("utf-8")
        if len(sendnow):
            mail.sendpost(
                email, sendnow,
                model.create_post_with_bugs(
                    (loginid, today, now, completed, planned, tags), None,
                    bugs))

        raise cherrypy.HTTPRedirect(cherrypy.url('/'))
Esempio n. 2
0
    def preferences(self, **kwargs):
        loginid = cherrypy.request.loginid

        cur = model.get_cursor()

        cur.execute('''SELECT email, reminderday, sendemail
                       FROM users WHERE userid = ?''',
                    (loginid,))
        r = cur.fetchone()
        if r is None:
            raise cherrypy.HTTPError(404, "User not found")

        email, reminderday, sendemail = r

        if cherrypy.request.method.upper() == 'POST':
            email = kwargs.pop('email')
            if email == '':
                email = None

            reminderday = kwargs.pop('reminderday')
            if reminderday == '-':
                reminderday = None
            else:
                reminderday = int(reminderday)

            sendemail = kwargs.pop('sendemail')
            if sendemail == '-':
                sendemail = None
            else:
                sendemail = int(sendemail)

            cur.execute('''UPDATE users
                           SET email = ?, reminderday = ?, sendemail = ?
                           WHERE userid = ?''',
                        (email, reminderday, sendemail, loginid))

            projectdata = []
            for k, v in kwargs.iteritems():
                if k.startswith('updateproject_') and v == '1':
                    project = k[14:]
                    if kwargs.get('project_%s' % project, False) == '1':
                        projectdata.append((loginid, project))

            cur.execute('''DELETE FROM userprojects WHERE userid = ?''', (loginid,))
            cur.executemany('''INSERT INTO userprojects (userid, projectname) VALUES (?, ?)''', projectdata)


        cur.execute('''SELECT projectname,
                         EXISTS(SELECT * FROM userprojects
                                WHERE userid = ?
                                  AND userprojects.projectname = projects.projectname)
                       FROM projects ORDER BY projectname''',
                    (loginid,))
        projects = cur.fetchall()

        return render('me.xhtml', email=email, reminderday=reminderday,
                      sendemail=sendemail, projects=projects)
Esempio n. 3
0
    def post(self, completed, planned, tags, isedit=False, **kwargs):
        loginid = cherrypy.request.loginid

        assert cherrypy.request.method.upper() == 'POST'

        cur = model.get_cursor()

        cur.execute('''SELECT IFNULL(email, userid)
                       FROM users
                       WHERE userid = ?''',
                    (loginid,))
        email, = cur.fetchone()

        completed = completed or None
        planned = planned or None
        tags = tags or None

        today = util.today().toordinal()
        now = util.now()
        bugs = kwargs_to_buglist(kwargs)

        if isedit:
            cur.execute('''UPDATE posts
                           SET completed = ?, planned = ?, tags = ?, posttime = ?
                           WHERE userid = ?
                             AND postdate = (
                               SELECT lastpostdate FROM (
                                 SELECT MAX(postdate) AS lastpostdate
                                 FROM posts AS p2
                                 WHERE p2.userid = ?
                               ) AS maxq
                             )''',
                        (completed, planned, tags, now, loginid, loginid))
        else:
            cur.execute('''INSERT INTO posts
                           (userid, postdate, posttime, completed, planned, tags)
                           VALUES (?, ?, ?, ?, ?, ?)''',
                        (loginid, today, now, completed, planned, tags))

        for bug in bugs:
            model.save_bugstatus(cur, loginid, bug, today)
        allteam, sendnow = model.get_userteam_emails(loginid)
        if isinstance(completed, str):
            completed = completed.decode("utf-8")
        if isinstance(planned, str):
            planned = planned.decode("utf-8")
        if isinstance(tags, str):
            tags = tags.decode("utf-8")
        if len(sendnow):
            mail.sendpost(email, sendnow,
                          model.create_post_with_bugs((loginid, today, now,
                                completed, planned, tags), None, bugs))

        raise cherrypy.HTTPRedirect(cherrypy.url('/'))
Esempio n. 4
0
    def project(self, projectname):
        cur = model.get_cursor()
        cur.execute('''SELECT projectname FROM projects WHERE projectname = ?''',
                    (projectname,))
        if cur.fetchone() is None:
            raise cherrypy.HTTPError(404, "Project not found")

        users = model.get_project_users(projectname)
        posts = model.get_project_posts(projectname)
        late = model.get_project_late(projectname)

        return render('project.xhtml', projectname=projectname, users=users,
                      posts=posts, late=late)
Esempio n. 5
0
    def admin(self, mail=None):
        loginid = cherrypy.request.loginid
        if loginid != cherrypy.request.app.config['weeklyupdates']['admin.userid']:
            raise cherrypy.HTTPError(403, "Must be logged in as an admin user")

        message = None
        if cherrypy.request.method.upper() == 'POST':
            cur = model.get_cursor()
            cur.execute('''UPDATE users
                           SET sendemail = NULL, reminderday = NULL
                           WHERE email = ? OR (email IS NULL AND userid = ?)''',
                        (mail, mail))
            message = "{} user(s) affected".format(cur.rowcount)
        return render('admin.xhtml', message=message)
Esempio n. 6
0
    def user(self, userid):
        cur = model.get_cursor()

        cur.execute('''SELECT userid FROM users WHERE userid = ?''',
                    (userid,))
        if cur.fetchone() is None:
            raise cherrypy.HTTPError(404, "User not found")

        userposts, thispost = model.get_user_posts(userid)

        projects = model.get_userprojects(userid)
        teamposts = model.get_teamposts(userid)

        return render('user.xhtml', userid=userid, projects=projects,
                      teamposts=teamposts, userposts=userposts)
Esempio n. 7
0
    def createproject(self, projectname):
        loginid = cherrypy.request.loginid

        if len(projectname) < 3:
            raise cherrypy.HTTPError(409, "Project name is not long enough")

        cur = model.get_cursor()
        cur.execute('''INSERT INTO projects (projectname, createdby)
                       VALUES (?, ?)''',
                    (projectname, loginid))
        cur.execute('''INSERT INTO userprojects (userid, projectname)
                       VALUES (?, ?)''',
                    (loginid, projectname))

        raise cherrypy.HTTPRedirect(cherrypy.url('/project/%s' % projectname))
Esempio n. 8
0
    def createproject(self, projectname):
        loginid = cherrypy.request.loginid

        if len(projectname) < 3:
            raise cherrypy.HTTPError(409, "Project name is not long enough")

        cur = model.get_cursor()
        cur.execute(
            '''INSERT INTO projects (projectname, createdby)
                       VALUES (?, ?)''', (projectname, loginid))
        cur.execute(
            '''INSERT INTO userprojects (userid, projectname)
                       VALUES (?, ?)''', (loginid, projectname))

        raise cherrypy.HTTPRedirect(cherrypy.url('/project/%s' % projectname))
Esempio n. 9
0
    def admin(self, mail=None):
        loginid = cherrypy.request.loginid
        if loginid != cherrypy.request.app.config['weeklyupdates'][
                'admin.userid']:
            raise cherrypy.HTTPError(403, "Must be logged in as an admin user")

        message = None
        if cherrypy.request.method.upper() == 'POST':
            cur = model.get_cursor()
            cur.execute(
                '''UPDATE users
                           SET sendemail = NULL, reminderday = NULL
                           WHERE email = ? OR (email IS NULL AND userid = ?)''',
                (mail, mail))
            message = "{} user(s) affected".format(cur.rowcount)
        return render('admin.xhtml', message=message)
Esempio n. 10
0
    def post(self, completed, planned, tags, isedit=False):
        loginid = cherrypy.request.loginid

        assert cherrypy.request.method.upper() == 'POST'

        cur = model.get_cursor()

        cur.execute('''SELECT IFNULL(email, userid)
                       FROM users
                       WHERE userid = ?''',
                    (loginid,))
        email, = cur.fetchone()

        completed = completed or None
        planned = planned or None
        tags = tags or None

        today = util.today().toordinal()
        now = util.now()

        if isedit:
            cur.execute('''UPDATE posts
                           SET completed = ?, planned = ?, tags = ?, posttime = ?
                           WHERE userid = ?
                             AND postdate = (
                               SELECT lastpostdate FROM (
                                 SELECT MAX(postdate) AS lastpostdate
                                 FROM posts AS p2
                                 WHERE p2.userid = ?
                               ) AS maxq
                             )''',
                        (completed, planned, tags, now, loginid, loginid))
        else:
            cur.execute('''INSERT INTO posts
                           (userid, postdate, posttime, completed, planned, tags)
                           VALUES (?, ?, ?, ?, ?, ?)''',
                        (loginid, today, now, completed, planned, tags))

        allteam, sendnow = model.get_userteam_emails(loginid)
        if len(sendnow):
            mail.sendpost(email, allteam, sendnow,
                          Post((loginid, today, now,
                                completed and completed.decode("utf-8"),
                                planned and planned.decode("utf-8"),
                                tags and tags.decode("utf-8"))))

        raise cherrypy.HTTPRedirect(cherrypy.url('/'))
Esempio n. 11
0
    def user(self, userid):
        cur = model.get_cursor()

        cur.execute('''SELECT userid FROM users WHERE userid = ?''',
                    (userid, ))
        if cur.fetchone() is None:
            raise cherrypy.HTTPError(404, "User not found")

        userposts, thispost = model.get_user_posts(userid)

        projects = model.get_userprojects(userid)
        teamposts = model.get_teamposts(userid)

        return render('user.xhtml',
                      userid=userid,
                      projects=projects,
                      teamposts=teamposts,
                      userposts=userposts,
                      team=[])
Esempio n. 12
0
    def project(self, projectname):
        cur = model.get_cursor()
        cur.execute(
            '''SELECT projectname FROM projects WHERE projectname = ?''',
            (projectname, ))
        if cur.fetchone() is None:
            raise cherrypy.HTTPError(404, "Project not found")

        users = model.get_project_users(projectname)
        posts = model.get_project_posts(projectname)
        late = model.get_project_late(projectname)
        iteration, daysleft = model.get_current_iteration()
        projects = model.get_projects()

        return render('project.xhtml',
                      projectname=projectname,
                      users=users,
                      posts=posts,
                      late=late,
                      team=[projectname],
                      iteration=iteration,
                      daysleft=daysleft,
                      projects=projects)
Esempio n. 13
0
    def login(self, **kwargs):
        if cherrypy.request.method.upper() == 'POST':
            cur = model.get_cursor()

            returnTo = kwargs.get('returnTo', cherrypy.url('/'))

            assertion = kwargs.pop('loginAssertion')
            if assertion == '':
                logged_out()
                raise cherrypy.HTTPRedirect(returnTo)

            try:
                result = browserid.verify(assertion, cherrypy.request.base)
            except browserid.ConnectionError:
                raise cherrypy.HTTPError(503, "Login connection error")
            except browserid.TrustError:
                raise cherrypy.HTTPError(409, "Invalid login")

            loginid = result['email']

            cur.execute('''SELECT userid FROM users
                           WHERE userid = ?''',
                        (loginid))
            if cur.fetchone() is None:
                cur.execute('''INSERT INTO users
                               (userid, email) VALUES (?, ?)''',
                            (loginid, loginid))
                logged_in(loginid)
                raise cherrypy.HTTPRedirect(cherrypy.url('/preferences'))
            logged_in(loginid)
            raise cherrypy.HTTPRedirect(returnTo)

        if cherrypy.request.loginid is not None:
            raise cherrypy.HTTPRedirect(cherrypy.url('/'))

        return render('login.xhtml')
Esempio n. 14
0
    def login(self, **kwargs):
        if cherrypy.request.method.upper() == 'POST':
            cur = model.get_cursor()

            returnTo = kwargs.get('returnTo', cherrypy.url('/'))

            assertion = kwargs.pop('loginAssertion')
            if assertion == '':
                logged_out()
                raise cherrypy.HTTPRedirect(returnTo)

            try:
                result = browserid.verify(assertion, cherrypy.request.base)
            except browserid.ConnectionError:
                raise cherrypy.HTTPError(503, "Login connection error")
            except browserid.TrustError:
                raise cherrypy.HTTPError(409, "Invalid login")

            loginid = result['email']

            cur.execute(
                '''SELECT userid FROM users
                           WHERE userid = ?''', (loginid, ))
            if cur.fetchone() is None:
                cur.execute(
                    '''INSERT INTO users
                               (userid) VALUES (?)''', (loginid, ))
                logged_in(loginid)
                raise cherrypy.HTTPRedirect(cherrypy.url('/preferences'))
            logged_in(loginid)
            raise cherrypy.HTTPRedirect(returnTo)

        if cherrypy.request.loginid is not None:
            raise cherrypy.HTTPRedirect(cherrypy.url('/'))

        return render('login.xhtml')
Esempio n. 15
0
    def preferences(self, **kwargs):
        loginid = cherrypy.request.loginid

        cur = model.get_cursor()

        cur.execute(
            '''SELECT bugmail, email, reminderday, sendemail
                       FROM users WHERE userid = ?''', (loginid, ))
        r = cur.fetchone()
        if r is None:
            raise cherrypy.HTTPError(404, "User not found")

        bugmail, email, reminderday, sendemail = r

        if cherrypy.request.method.upper() == 'POST':
            bugmail = kwargs.pop('bugmail')
            if bugmail == '' or bugmail == loginid:
                bugmail = None

            email = kwargs.pop('email')
            if email == '' or email == loginid:
                email = None

            reminderday = kwargs.pop('reminderday')
            if reminderday == '-':
                reminderday = None
            else:
                reminderday = int(reminderday)

            sendemail = kwargs.pop('sendemail')
            if sendemail == '-':
                sendemail = None
            else:
                sendemail = int(sendemail)

            cur.execute(
                '''UPDATE users
                           SET bugmail = ?, email = ?, reminderday = ?, sendemail = ?
                           WHERE userid = ?''',
                (bugmail, email, reminderday, sendemail, loginid))

            projectdata = []
            for k, v in kwargs.iteritems():
                if k.startswith('updateproject_') and v == '1':
                    project = k[14:]
                    if kwargs.get('project_%s' % project, False) == '1':
                        projectdata.append((loginid, project))

            cur.execute('''DELETE FROM userprojects WHERE userid = ?''',
                        (loginid, ))
            cur.executemany(
                '''INSERT INTO userprojects (userid, projectname) VALUES (?, ?)''',
                projectdata)

        cur.execute(
            '''SELECT projectname,
                         EXISTS(SELECT * FROM userprojects
                                WHERE userid = ?
                                  AND userprojects.projectname = projects.projectname)
                       FROM projects ORDER BY projectname''', (loginid, ))
        projects = cur.fetchall()

        return render('me.xhtml',
                      bugmail=bugmail,
                      email=email,
                      reminderday=reminderday,
                      sendemail=sendemail,
                      projects=projects,
                      userid=loginid,
                      team=[])