Ejemplo n.º 1
0
 def collection_addOwn(self, token, newname):
     username = self.tokenOper_get_username(token)
     newuuid = utils.GenerateUUID()
     lastupdate = utils.GenerateUUID()
     self.cursor.execute('INSERT INTO collection VALUES (?, ?, ?, ?);',
                         (newuuid, newname, username, lastupdate))
     return newuuid
Ejemplo n.º 2
0
 def todo_add(self, token):
     username = self.tokenOper_get_username(token)
     newuuid = utils.GenerateUUID()
     lastupdate = utils.GenerateUUID()
     returnedData = (
         newuuid,
         username,
         '',
         lastupdate,
     )
     self.cursor.execute('INSERT INTO todo VALUES (?, ?, ?, ?);',
                         returnedData)
     return returnedData
Ejemplo n.º 3
0
    def admin_add(self, token, newname):
        username = self.tokenOper_get_username(token)
        if not self.tokenOper_is_admin(username):
            raise Exception('Permission denied.')

        newpassword = utils.ComputePasswordHash(utils.GenerateUUID())
        self.cursor.execute('INSERT INTO user VALUES (?, ?, ?, ?);',
                            (newname, newpassword, 0, utils.GenerateSalt()))
        return (newname, False)
Ejemplo n.º 4
0
    def calendar_add(self, token, belongTo, title, description,
                     eventDateTimeStart, eventDateTimeEnd, loopRules,
                     timezoneOffset):
        self.tokenOper_check_valid(token)

        newuuid = utils.GenerateUUID()
        lastupdate = utils.GenerateUUID()

        # analyse loopRules and output following 2 fileds.
        loopDateTimeStart = eventDateTimeStart
        loopDateTimeEnd = dt.ResolveLoopStr(loopRules, eventDateTimeStart,
                                            timezoneOffset)

        self.cursor.execute(
            'INSERT INTO calendar VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);',
            (newuuid, belongTo, title, description, lastupdate,
             eventDateTimeStart, eventDateTimeEnd, timezoneOffset, loopRules,
             loopDateTimeStart, loopDateTimeEnd))
        return newuuid
Ejemplo n.º 5
0
    def collection_updateOwn(self, token, uuid, newname, lastChange):
        self.tokenOper_check_valid(token)

        lastupdate = utils.GenerateUUID()
        self.cursor.execute(
            'UPDATE collection SET [ccn_name] = ?, [ccn_lastChange] = ? WHERE [ccn_uuid] = ? AND [ccn_lastChange] = ?;',
            (newname, lastupdate, uuid, lastChange))
        if self.cursor.rowcount != 1:
            raise Exception(
                'Fail to update due to no matched rows or too much rows.')
        return lastupdate
Ejemplo n.º 6
0
    def todo_update(self, token, uuid, data, lastChange):
        # check valid token
        self.tokenOper_check_valid(token)

        # update
        newLastChange = utils.GenerateUUID()
        self.cursor.execute(
            'UPDATE todo SET [ccn_data] = ?, [ccn_lastChange] = ? WHERE [ccn_uuid] = ? AND [ccn_lastChange] = ?;',
            (data, newLastChange, uuid, lastChange))
        if self.cursor.rowcount != 1:
            raise Exception(
                'Fail to update due to no matched rows or too much rows.')
        return newLastChange
Ejemplo n.º 7
0
    def collection_addSharing(self, token, uuid, target, lastChange):
        self.tokenOper_check_valid(token)

        lastupdate = utils.GenerateUUID()
        self.cursor.execute(
            'UPDATE collection SET [ccn_lastChange] = ? WHERE [ccn_uuid] = ? AND [ccn_lastChange] = ?;',
            (lastupdate, uuid, lastChange))
        if self.cursor.rowcount != 1:
            raise Exception(
                'Fail to delete due to no matched rows or too much rows.')

        self.cursor.execute(
            'SELECT * FROM share WHERE [ccn_uuid] = ? AND [ccn_target] = ?;',
            (uuid, target))
        if len(self.cursor.fetchall()) != 0:
            raise Exception('Fail to insert duplicated item.')
        self.cursor.execute('INSERT INTO share VALUES (?, ?);', (uuid, target))

        return lastupdate
Ejemplo n.º 8
0
    def collection_deleteSharing(self, token, uuid, target, lastChange):
        self.tokenOper_check_valid(token)

        lastupdate = utils.GenerateUUID()
        self.cursor.execute(
            'UPDATE collection SET [ccn_lastChange] = ?, WHERE [ccn_uuid] = ? AND [ccn_lastChange] = ?;',
            (lastupdate, uuid, lastChange))
        if self.cursor.rowcount != 1:
            raise Exception(
                'Fail to delete due to no matched rows or too much rows.')

        self.cursor.execute(
            'DELETE FROM share WHERE [ccn_uuid] = ? AND [ccn_target] = ?;',
            (uuid, target))
        if self.cursor.rowcount != 1:
            raise Exception(
                'Fail to delete due to no matched rows or too much rows.')

        return lastupdate
Ejemplo n.º 9
0
    def calendar_update(self, token, uuid, lastChange, **optArgs):
        self.tokenOper_check_valid(token)

        # get prev data
        self.cursor.execute(
            'SELECT * FROM calendar WHERE [ccn_uuid] = ? AND [ccn_lastChange] = ?;',
            (uuid, lastChange))
        analyseData = list(self.cursor.fetchone())

        # construct update data
        lastupdate = utils.GenerateUUID()
        sqlList = [
            '[ccn_lastChange] = ?',
        ]
        argumentsList = [
            lastupdate,
        ]

        # analyse opt arg
        reAnalyseLoop = False

        cache = optArgs.get('belongTo', None)
        if cache is not None:
            sqlList.append('[ccn_belongTo] = ?')
            argumentsList.append(cache)
        cache = optArgs.get('title', None)
        if cache is not None:
            sqlList.append('[ccn_title] = ?')
            argumentsList.append(cache)
        cache = optArgs.get('description', None)
        if cache is not None:
            sqlList.append('[ccn_description] = ?')
            argumentsList.append(cache)
        cache = optArgs.get('eventDateTimeStart', None)
        if cache is not None:
            sqlList.append('[ccn_eventDateTimeStart] = ?')
            argumentsList.append(cache)
            reAnalyseLoop = True
            analyseData[5] = cache
        cache = optArgs.get('eventDateTimeEnd', None)
        if cache is not None:
            sqlList.append('[ccn_eventDateTimeEnd] = ?')
            argumentsList.append(cache)
        cache = optArgs.get('loopRules', None)
        if cache is not None:
            sqlList.append('[ccn_loopRules] = ?')
            argumentsList.append(cache)
            reAnalyseLoop = True
            analyseData[8] = cache
        cache = optArgs.get('timezoneOffset', None)
        if cache is not None:
            sqlList.append('[ccn_timezoneOffset] = ?')
            argumentsList.append(cache)
            reAnalyseLoop = True
            analyseData[7] = cache

        if reAnalyseLoop:
            # re-compute loop data and upload it into list
            sqlList.append('[ccn_loopDateTimeStart] = ?')
            argumentsList.append(analyseData[5])
            sqlList.append('[ccn_loopDateTimeEnd] = ?')
            argumentsList.append(
                dt.ResolveLoopStr(analyseData[8], analyseData[5],
                                  analyseData[7]))

        # execute
        argumentsList.append(uuid)
        self.cursor.execute(
            'UPDATE calendar SET {} WHERE [ccn_uuid] = ?;'.format(
                ', '.join(sqlList)), tuple(argumentsList))
        if self.cursor.rowcount != 1:
            raise Exception(
                'Fail to update due to no matched rows or too much rows.')
        return lastupdate