<commit_before>package EnsEMBL::Users::Command::Account::Membership;

### Allows the user to accept or decline a membership invitation, or allows the admin user to allow or ignore a membership request from a user

use strict;
use warnings;

use base qw(EnsEMBL::Users::Command::Account);

sub process {
  my $self        = shift;
  my $object      = $self->object;
  my $hub         = $self->hub;
  my $user        = $hub->user;
  my $membership  = $hub->param('id') ? $object->fetch_membership($hub->param('id')) : undef or return $self->redirect_message($object->get_message_code('MESSAGE_GROUP_NOT_FOUND'), {'error' => 1});

  $membership->save('user' => $user) if $self->modify_membership($membership);

  return $self->ajax_redirect($self->redirect_url);
}

sub redirect_url {
  my $self  = shift;
  my $hub   = $self->hub;
  $self->{'_redirect_url'} = shift if @_;
  return $self->{'_redirect_url'} ? $hub->url($self->{'_redirect_url'}) : $self->internal_referer;
}

sub modify_membership {} # implemented in child classes

1;<commit_msg>fetch membership object for active group only<commit_after>package EnsEMBL::Users::Command::Account::Membership;

### Allows the user to accept or decline a membership invitation, or allows the admin user to allow or ignore a membership request from a user

use strict;
use warnings;

use base qw(EnsEMBL::Users::Command::Account);

sub process {
  my $self        = shift;
  my $object      = $self->object;
  my $hub         = $self->hub;
  my $user        = $hub->user;
  my $membership  = $hub->param('id')
    ? $object->fetch_membership($hub->param('id'), {'with_objects' => 'group', 'query' => ['group.status' => 'active']})
    : undef or return $self->redirect_message($object->get_message_code('MESSAGE_GROUP_NOT_FOUND'), {'error' => 1, 'back' => $self->internal_referer})
  ;

  $membership->save('user' => $user) if $self->modify_membership($membership);

  return $self->ajax_redirect($self->redirect_url);
}

sub redirect_url {
  my $self  = shift;
  my $hub   = $self->hub;
  $self->{'_redirect_url'} = shift if @_;
  return $self->{'_redirect_url'} ? $hub->url($self->{'_redirect_url'}) : $self->internal_referer;
}

sub modify_membership {} # implemented in child classes

1;
{'fraction_non_alphanumeric': 0.1650268336314848, 'fraction_numerical': 0.0017889087656529517, 'mean_word_length': 4.523456790123457, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1084739', 'n_tokens_mistral': 737, 'n_tokens_neox': 724, 'n_words': 184}