示例#1
0
 def _group_exists(self, con, gid):
     cur = self._dbh.execute(con,
             "SELECT name FROM groups WHERE gid == %s",
             gid - self._go)
     if len(cur.fetchall()) != 1:
         raise I.GroupNotFound("Group not found",
                 "searching for group in database", gid)
示例#2
0
 def delete(self, con, gid, current):
     n = gid - self._go
     cur = self._dbh.execute(con,
             "DELETE FROM groups WHERE gid == %s", n)
     if cur.rowcount != 1:
         raise I.GroupNotFound("Group not found",
                 "deleting group", gid)
     con.commit()
示例#3
0
 def getByName(self, con, name, current):
     cur = self._dbh.execute(con,
             "SELECT gid, name, description FROM groups "
             "WHERE name == %s", name)
     res = cur.fetchall()
     if len(res) != 1:
         raise I.GroupNotFound("Group not found",
                 "Could not get group information for  %s" % name, -1)
     return self._db2groups(res)[0]
示例#4
0
 def getById(self, con, gid, current):
     cur = self._dbh.execute(con,
             "SELECT gid, name, description FROM groups "
             "WHERE gid == %s", gid - self._go)
     res = cur.fetchall()
     if len(res) != 1:
         raise I.GroupNotFound("Group not found",
                 "retrieving group by id" ,gid)
     return self._db2groups(res)[0]
示例#5
0
 def delUserFromGroups(self, con, uid, groups, current):
     ids = tuple((i - self._go for i in groups))
     ps = '(' + ', '.join(('%s' for x in ids)) +')'
     cur = self._dbh.execute(con,
             "DELETE FROM real_group_entries "
             "WHERE uid == %s AND gid IN " + ps,
             uid - self._uo, *ids)
     if cur.rowcount != len(groups):
         if current.ctx.get("PartialStrategy") != "Partial":
             #XXX: search for wrong uid and raise I.GroupNotFound
             raise I.GroupNotFound("Group not found",
                     "Some groups were not found", -1)
     con.commit()
示例#6
0
 def getGroups(self, con, groupids, current):
     ids = tuple((i - self._go for i in groupids))
     ps = '(' + ', '.join(('%s' for x in ids)) +')'
     cur = self._dbh.execute(con,
             "SELECT gid, name, description FROM groups "
             + "WHERE gid IN " + ps, *ids)
     res = self._db2groups(cur.fetchall())
     if (len(res) != len(groupids)
             and current.ctx.get("PartialStrategy") != "Partial"):
         retrieved = set( (g.gid for g in res) )
         for i in groupids:
             if i not in retrieved:
                 raise I.GroupNotFound("Group not found",
                         "retrieving multiple groups", i)
     return res
示例#7
0
 def modify(self, con, group, current):
     if not self._good_name.match(group.name):
         raise C.ValueError("Invalid group name: %s" % group.name)
     try:
         cur = self._dbh.execute(con,
                                 "UPDATE groups SET "
                                 "name=%s, description=%s "
                                 "WHERE gid == %s",
                                 group.name, group.description,
                                 group.gid - self._go)
     except self._dbh.IntegrityError:
         raise C.AlreadyExistsError("Group already exists",
                                    group.name)
     if cur.rowcount != 1:
         raise I.GroupNotFound("Group not found",
                 "modifying group", group.gid)
     con.commit()