Exemple #1
0
def propose_remove_role_admins(txn_key, batch_key, proposal_id, role_id,
                               user_id, reason, metadata):
    propose = role_transaction_pb2.ProposeRemoveRoleAdmin(
        proposal_id=proposal_id,
        role_id=role_id,
        user_id=user_id,
        reason=reason,
        metadata=metadata,
    )

    inputs = [
        addresser.user.address(user_id),
        addresser.proposal.address(role_id, user_id),
        addresser.role.admin.address(role_id, user_id),
        addresser.role.address(role_id),
    ]

    outputs = [addresser.proposal.address(role_id, user_id)]

    rbac_payload = rbac_payload_pb2.RBACPayload(
        content=propose.SerializeToString(),
        message_type=rbac_payload_pb2.RBACPayload.PROPOSE_REMOVE_ROLE_ADMIN,
    )

    return make_header_and_batch(rbac_payload, inputs, outputs, txn_key,
                                 batch_key)
Exemple #2
0
def apply_propose_remove(header, payload, state):
    role_admins_payload = role_transaction_pb2.ProposeRemoveRoleAdmin()
    role_admins_payload.ParseFromString(payload.content)

    role_admins_address = addresser.make_role_admins_address(
        role_id=role_admins_payload.role_id,
        user_id=role_admins_payload.user_id)

    proposal_address = addresser.make_proposal_address(
        object_id=role_admins_payload.role_id,
        related_id=role_admins_payload.user_id)

    state_entries = role_validator.validate_role_rel_proposal(
        header, role_admins_payload, role_admins_address, state, True)

    if not proposal_validator.has_no_open_proposal(
            state_entries=state_entries,
            object_id=role_admins_payload.role_id,
            related_id=role_admins_payload.user_id,
            proposal_address=proposal_address,
            proposal_type=proposal_state_pb2.Proposal.REMOVE_ROLE_ADMINS,
    ):
        raise InvalidTransaction(
            "There is already an open proposal for REMOVE_ROLE_ADMINS "
            "with role id {} and user id {}".format(
                role_admins_payload.role_id, role_admins_payload.user_id))

    state_change.propose_role_action(
        state_entries=state_entries,
        header=header,
        payload=role_admins_payload,
        address=proposal_address,
        proposal_type=proposal_state_pb2.Proposal.REMOVE_ROLE_ADMINS,
        state=state,
    )