def test_upd_group(self): _add_test_user("testuser1") _add_test_user("testuser2") g = groups.Group(name="testgroup", users=["testuser1"]) g.add() g = groups.get(name="testgroup") g.users = ["testuser2"] g.update() g = groups.get(name="testgroup") self.assertEqual(g.users, ["testuser2"])
def delete_group(name): """Delete an arkOS LDAP group""" try: g = groups.get(name=name) g.delete() logger.success('ctl:grp:delete', 'Deleted {0}'.format(name)) except Exception as e: raise CLIException(str(e))
def get(self, id): g = groups.get(id) if id and not g: abort(404) if type(g) == list: return jsonify(groups=[x.as_dict() for x in g]) else: return jsonify(group=g.as_dict())
def get(self, id): g = groups.get(id) if id and not g: abort(404) if isinstance(g, groups.Group): return jsonify(group=g.serialized) else: return jsonify(groups=[x.serialized for x in g])
def delete(self, id): g = groups.get(id) if not g: abort(404) try: g.delete() except errors.InvalidConfigError as e: return jsonify(errors={"msg": str(e)}), 422 return Response(status=204)
def delete(self, id): g = groups.get(id) if not g: abort(404) try: g.delete() except Exception, e: resp = jsonify(message="Group couldn't be deleted: %s" % str(e)) resp.status_code = 422 return resp
def put(self, id): data = request.get_json()["group"] g = groups.get(id) if not g: abort(404) g.users = [str(u) for u in data["users"]] try: g.update() except errors.InvalidConfigError as e: return jsonify(errors={"msg": str(e)}), 422 return jsonify(group=g.serialized)
def mod_group(name, operation, username): """Add/remove users from an arkOS LDAP group""" try: g = groups.get(name=name) if operation == "add": g.users.append(username) else: g.users.remove(username) g.update() logger.success('ctl:grp:mod', 'Modified {0}'.format(name)) except Exception as e: raise CLIException(str(e))
def put(self, id): data = json.loads(request.data)["group"] g = groups.get(id) if not g: abort(404) g.users = [str(u) for u in data["users"]] try: g.update() except Exception, e: resp = jsonify(message="Group couldn't be updated: %s" % str(e)) resp.status_code = 422 return resp
def list_groups(): """List groups""" try: data = [x.serialized for x in groups.get()] for x in data: click.echo( click.style(x["name"], fg="white", bold=True) + click.style(" ({0})".format(x["id"]), fg="green")) click.echo( click.style(" * Members: ", fg="yellow") + ", ".join(x["users"])) except Exception as e: raise CLIException(str(e))
def test_del_group(self): g = groups.Group(name="testgroup", users=[]) g.add() g = groups.get(name="testgroup") g.delete() self.assertIsNone(groups.get(name="testgroup"))