Exemplo n.º 1
0
    def _insert_or_update_interaction(self, trans, params):
        tdb = transdb.TransDbAccess(self.db, trans)
        r = []

        for p in params:
            param = UserParam()
            param.parse_xml(str(p), self.username)

            prefix_id = tdb.access_to_prefix(param.prefix, self.user_id)
            if prefix_id is None:
                r.append(False)
                continue

            param_id, param_user_id = tdb.get_param_id(param.name)

            if param_id is None:
                tdb.insert_param(param, self.user_id, prefix_id)
                r.append(True)
            elif param_user_id == self.user_id:
                tdb.update_param(param, param_id, prefix_id, self.user_id)
                r.append(True)
            else:
                r.append(False)

        return r
Exemplo n.º 2
0
    def _remove_sets_interaction(self, trans, sets):
        tdb = transdb.TransDbAccess(self.db, trans)

        r = []

        for s in sets:
            user_set = UserSet()

            user_set.parse_xml(str(s), self.username)

            if not all([
                    tdb.has_access_to_prefix(p, self.user_id)
                    for p in set(user_set.prefixes)
            ]):
                r.append(False)
                continue

            set_id, set_user_id = tdb.get_set_id(user_set.name)
            if self.user_id == set_user_id:
                tdb.update_set_mod_time(set_id, deleted=True)
                r.append(True)
            else:
                r.append(False)

        return r
Exemplo n.º 3
0
    def _do_it_interaction(self, trans):
        tdb = transdb.TransDbAccess(self.db, trans)

        self.get_prefixes(tdb)
        self.get_params(tdb)
        self.get_sets(tdb)

        return (self.params, self.sets)
Exemplo n.º 4
0
	def _get_remarks_interaction(self, trans, time, prefixes, user_id):
		tdb = transdb.TransDbAccess(self.db, trans)

		prefixes_ids = tdb.get_prefix_ids_for_names(prefixes);
		user_prefixes = tdb.get_user_prefixes(user_id)

		new_prefixes = user_prefixes - prefixes_ids
		known_prefixes = user_prefixes & prefixes_ids

		return tdb.get_remarks(time, known_prefixes, new_prefixes)
Exemplo n.º 5
0
	def _post_remark_interaction(self, trans, user_id, username, remark):
		tdb = transdb.TransDbAccess(self.db, trans)

		tree = etree.fromstring(remark.data)
		remark_node = tree.xpath("/remark")[0]
		remark_node.attrib['author'] = username
		prefix = remark_node.attrib['prefix']

		prefix_id = tdb.access_to_prefix(prefix, user_id)
		if prefix_id is None:
			raise xmlrpc.Fault(-1, "User is not allowed to send remarks for this base")

		tdb.insert_remark(etree.tostring(tree), prefix_id)
Exemplo n.º 6
0
 def _login_interaction(self, trans, user, password):
     tdb = transdb.TransDbAccess(self.service.db, trans)
     ok, user_id, username = tdb.login(user, password)
     if ok:
         token = self.service.sessions.new(user_id, username)
         return token
     else:
         # cfglogin
         ok, user_id, username = tdb.autologin(user, password)
         if ok:
             token = self.service.sessions.new(user_id, username)
             return token
         else:
             raise xmlrpc.Fault(-1, "Incorrect username and password")
Exemplo n.º 7
0
    def _remove_interaction(self, trans, params):
        r = []
        tdb = transdb.TransDbAccess(self.db, trans)
        for p in params:
            param = UserParam()
            param.parse_xml(str(p), self.username)

            if not tdb.has_access_to_prefix(param.prefix, self.user_id):
                r.append(False)
                continue

            r.append(tdb.remove_param(param.prefix, param.name, self.user_id))

        return r
Exemplo n.º 8
0
    def _insert_or_update_sets_interaction(self, trans, sets):
        tdb = transdb.TransDbAccess(self.db, trans)

        r = []

        for s in sets:
            user_set = UserSet()
            user_set.parse_xml(str(s), self.username)

            ret = self._insert_or_update_set(user_set, tdb)

            r.append(ret)

        return r
Exemplo n.º 9
0
 def _fetch_cfglogin_interaction(self, trans):
     tdb = transdb.TransDbAccess(self.service.db, trans)
     self.cfglogin_prefixes = tdb.fetch_cfglogin()
Exemplo n.º 10
0
 def _hash_update_interaction(self, trans, prefix, config_hash):
     tdb = transdb.TransDbAccess(self.service.db, trans)
     tdb.hash_update(prefix, config_hash)