示例#1
0
def test_basic_request(graph, groups, permissions, session, standard_graph,
                       users):  # noqa: F811
    group_sre = groups["team-sre"]
    group_not_sre = [g for name, g in groups.items() if name != "team-sre"]

    assert not any([
        get_requests_by_group(session, group, status="pending").all()
        for group in groups.values() if not is_role_user(session, group=group)
    ]), "no group should start with pending requests"

    group_sre.add_member(users["*****@*****.**"],
                         users["*****@*****.**"],
                         reason="for the lulz")
    session.commit()

    request_not_sre = [
        get_requests_by_group(session, group, status="pending").all()
        for group in group_not_sre
    ]
    assert not any(
        request_not_sre), "only affected group should show pending requests"
    request_sre = get_requests_by_group(session, group_sre,
                                        status="pending").all()
    assert len(request_sre) == 1, "affected group should have request"

    request = session.query(Request).filter_by(id=request_sre[0].id).scalar()
    request.update_status(users["*****@*****.**"], "actioned",
                          "for being a good person")
    session.commit()

    assert not any([
        get_requests_by_group(session, group, status="pending").all()
        for group in groups.values()
    ]), "no group should have requests after being actioned"
示例#2
0
def test_basic_request(graph, groups, permissions, session, standard_graph, users):  # noqa: F811
    group_sre = groups["team-sre"]
    group_not_sre = [g for name, g in iteritems(groups) if name != "team-sre"]

    assert not any(
        [
            get_requests_by_group(session, group, status="pending").all()
            for group in itervalues(groups)
        ]
    ), "no group should start with pending requests"

    group_sre.add_member(users["*****@*****.**"], users["*****@*****.**"], reason="for the lulz")
    session.commit()

    request_not_sre = [
        get_requests_by_group(session, group, status="pending").all() for group in group_not_sre
    ]
    assert not any(request_not_sre), "only affected group should show pending requests"
    request_sre = get_requests_by_group(session, group_sre, status="pending").all()
    assert len(request_sre) == 1, "affected group should have request"

    request = session.query(Request).filter_by(id=request_sre[0].id).scalar()
    request.update_status(users["*****@*****.**"], "actioned", "for being a good person")
    session.commit()

    assert not any(
        [
            get_requests_by_group(session, group, status="pending").all()
            for group in itervalues(groups)
        ]
    ), "no group should have requests after being actioned"
示例#3
0
    def get(self, group_id=None, name=None):
        group = Group.get(self.session, group_id, name)
        if not group:
            return self.notfound()

        status = self.get_argument("status", None)
        offset = int(self.get_argument("offset", 0))
        limit = int(self.get_argument("limit", 100))
        if limit > 9000:
            limit = 9000

        requests = get_requests_by_group(self.session, group, status=status).order_by(
            Request.requested_at.desc()
        )
        members = group.my_members()

        total = requests.count()
        requests = requests.offset(offset).limit(limit)

        current_user_role = {
            'is_owner': user_role_index(self.current_user, members) in OWNER_ROLE_INDICES,
            'is_approver': user_role_index(self.current_user, members) in APPROVER_ROLE_INDICES,
            'is_manager': user_role(self.current_user, members) == "manager",
            'role': user_role(self.current_user, members),
             }

        self.render(
            "group-requests.html", group=group, requests=requests,
            members=members, status=status, statuses=REQUEST_STATUS_CHOICES,
            offset=offset, limit=limit, total=total, current_user_role=current_user_role,
        )
示例#4
0
    def get(self, *args: Any, **kwargs: Any) -> None:
        name = self.get_path_argument("name")

        group = Group.get(self.session, name=name)
        if not group:
            return self.notfound()

        status = self.get_argument("status", None)
        offset = int(self.get_argument("offset", 0))
        limit = int(self.get_argument("limit", 100))
        if limit > 9000:
            limit = 9000

        requests = get_requests_by_group(self.session, group,
                                         status=status).order_by(
                                             Request.requested_at.desc())
        members = group.my_members()

        total = requests.count()
        requests = requests.offset(offset).limit(limit)

        current_user_role = {
            "is_owner": user_role_index(self.current_user,
                                        members) in OWNER_ROLE_INDICES,
            "is_approver": user_role_index(self.current_user, members)
            in APPROVER_ROLE_INDICES,
            "is_manager": user_role(self.current_user, members) == "manager",
            "role": user_role(self.current_user, members),
        }

        self.render(
            "group-requests.html",
            group=group,
            requests=requests,
            members=members,
            status=status,
            statuses=REQUEST_STATUS_CHOICES,
            offset=offset,
            limit=limit,
            total=total,
            current_user_role=current_user_role,
        )