Problem/Motivation

I've created a custom module to alter the whole workflow.
My module doesn't allow to go from "pending" to "allowed". When I submit the "GroupMembershipApproveForm" then transition is not allowed but the message is "Membership request approved" because the module forgot to validate the transition. (Same for create,reject)

I know this is not possible to happen without custom module, but programmatically validation is missing.

Steps to reproduce

Change the workflow. (Disable to go from "pending" to "allowed")
Request membership
Allow membership
Form message: "Membership request approved"
But state is still pending.

Proposed resolution

Return a bool

  public function updateStatus(GroupContentInterface $group_content, $transition_id): bool {
    $state_item = $group_content->get(GroupMembershipRequest::STATUS_FIELD)->first();
    if ($state_item->isTransitionAllowed($transition_id)) {
      $state_item->applyTransitionById($transition_id);
      $group_content->set('grequest_updated_by', $this->currentUser->id());
+      return true;
    }
+    return false;
  }

Check it before update

   public function approve(GroupContentInterface $group_content, array $group_roles = []) {
    $is_updated = $this->updateStatus($group_content, GroupMembershipRequest::TRANSITION_APPROVE);
    $result = $is_updated && $group_content->save() == SAVED_UPDATED;

Comments

kecsot created an issue. See original summary.

kecsot’s picture

kecsot’s picture

Status: Active » Needs review
lobsterr’s picture

StatusFileSize
new1.26 KB

I think it would a correct way to handle it. I also added a validation for group content

kecsot’s picture

Tested and it works well.
Thank you!

  • LOBsTerr committed 1d9c97c on 1.0.x
    Issue #3298290 by kecsot, LOBsTerr: Validate Transition before update...
lobsterr’s picture

Status: Needs review » Fixed

Thank you for your contribution

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.