Split pending organisations into a separate list and default to only returning organisations a user is an accepted member of (Fixes #1)
This commit is contained in:
@@ -80,7 +80,7 @@ class OrganisationMembersController extends SimpleController
|
|||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($config['organisation']['membership']['single_membership'] && $currentUser->organisations()->count() > 0) {
|
if ($config['organisation']['membership']['single_membership'] && $currentUser->organisations(true)->count() > 0) {
|
||||||
$ms->addMessageTranslated('danger', 'ORGANISATION.JOIN_REQUEST.ALREADY_IN_ONE');
|
$ms->addMessageTranslated('danger', 'ORGANISATION.JOIN_REQUEST.ALREADY_IN_ONE');
|
||||||
return $response->withJson([], 400);
|
return $response->withJson([], 400);
|
||||||
}
|
}
|
||||||
@@ -294,7 +294,7 @@ class OrganisationMembersController extends SimpleController
|
|||||||
|
|
||||||
// Begin transaction - DB will be rolled back if an exception occurs
|
// Begin transaction - DB will be rolled back if an exception occurs
|
||||||
Capsule::transaction(function () use ($organisation, $currentUser) {
|
Capsule::transaction(function () use ($organisation, $currentUser) {
|
||||||
$currentUser->organisations()->detach($organisation->id);
|
$currentUser->organisations(true)->detach($organisation->id);
|
||||||
|
|
||||||
// Create activity record
|
// Create activity record
|
||||||
$this->ci->userActivityLogger->info("User {$currentUser->user_name} left organisation {$organisation->name}.", [
|
$this->ci->userActivityLogger->info("User {$currentUser->user_name} left organisation {$organisation->name}.", [
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class OrganisationRegistrationController extends SimpleController
|
|||||||
throw new ForbiddenException();
|
throw new ForbiddenException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($config['organisation']['membership']['single_membership'] && $currentUser->organisations()->count() > 0) {
|
if ($config['organisation']['membership']['single_membership'] && $currentUser->organisations(true)->count() > 0) {
|
||||||
$ms->addMessageTranslated('danger', 'ORGANISATION.REGISTRATION.ALREADY_IN_ONE', $data);
|
$ms->addMessageTranslated('danger', 'ORGANISATION.REGISTRATION.ALREADY_IN_ONE', $data);
|
||||||
return $response->withJson([], 400);
|
return $response->withJson([], 400);
|
||||||
}
|
}
|
||||||
@@ -600,7 +600,7 @@ class OrganisationRegistrationController extends SimpleController
|
|||||||
throw new ForbiddenException();
|
throw new ForbiddenException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($config['organisation']['membership']['single_membership'] && $currentUser->organisations()->count() > 0) {
|
if ($config['organisation']['membership']['single_membership'] && $currentUser->organisations(true)->count() > 0) {
|
||||||
throw new BadRequestException();
|
throw new BadRequestException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ class UserController extends UFUserController
|
|||||||
foreach ($fieldValue as $field) {
|
foreach ($fieldValue as $field) {
|
||||||
$newOrganisations[$field['organisation_id']] = ['flag_admin' => $field['flag_admin'] == 1];
|
$newOrganisations[$field['organisation_id']] = ['flag_admin' => $field['flag_admin'] == 1];
|
||||||
}
|
}
|
||||||
$user->organisations()->sync($newOrganisations);
|
$user->organisations(true)->sync($newOrganisations);
|
||||||
} else {
|
} else {
|
||||||
$user->$fieldName = $fieldValue;
|
$user->$fieldName = $fieldValue;
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|||||||
@@ -32,7 +32,30 @@ class User extends UFUser
|
|||||||
*
|
*
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||||
*/
|
*/
|
||||||
public function organisations()
|
public function organisations($withPending = false)
|
||||||
|
{
|
||||||
|
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
|
||||||
|
$classMapper = static::$ci->classMapper;
|
||||||
|
|
||||||
|
$query = $this->belongsToMany(
|
||||||
|
$classMapper->getClassMapping('organisation'), 'organisation_members', 'user_id', 'organisation_id'
|
||||||
|
)
|
||||||
|
->orderBy('organisations.name', 'asc')
|
||||||
|
->withPivot(['flag_admin', 'flag_approved']);
|
||||||
|
|
||||||
|
if ($withPending !== true) {
|
||||||
|
$query = $query->wherePivot('flag_approved', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all organisations this user is attempting to join.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||||
|
*/
|
||||||
|
public function pendingOrganisations()
|
||||||
{
|
{
|
||||||
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
|
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
|
||||||
$classMapper = static::$ci->classMapper;
|
$classMapper = static::$ci->classMapper;
|
||||||
@@ -41,7 +64,8 @@ class User extends UFUser
|
|||||||
$classMapper->getClassMapping('organisation'), 'organisation_members', 'user_id', 'organisation_id'
|
$classMapper->getClassMapping('organisation'), 'organisation_members', 'user_id', 'organisation_id'
|
||||||
)
|
)
|
||||||
->orderBy('organisations.name', 'asc')
|
->orderBy('organisations.name', 'asc')
|
||||||
->withPivot(['flag_admin', 'flag_approved']);
|
->withPivot(['flag_admin', 'flag_approved'])
|
||||||
|
->wherePivot('flag_approved', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,7 +89,7 @@ class User extends UFUser
|
|||||||
->where('approver_id', $this->id)
|
->where('approver_id', $this->id)
|
||||||
->update(['approver_id' => null]);
|
->update(['approver_id' => null]);
|
||||||
|
|
||||||
$this->organisations()->detach();
|
$this->organisations(true)->detach();
|
||||||
$this->refresh();
|
$this->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class UserSprunje extends UFUserSprunje
|
|||||||
$query = parent::baseQuery();
|
$query = parent::baseQuery();
|
||||||
|
|
||||||
// Join user's organisations
|
// Join user's organisations
|
||||||
return $query->joinOrganisations()->with('organisations');
|
return $query->joinOrganisations(true)->with('organisations')->with('pendingOrganisations');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
<a href="#" data-toggle="collapse" data-target="#submenu-organisations" aria-expanded="false"><i class="fa fa-fw fa-sitemap"></i> <span>{{ translate("ORGANISATION.SELF") }}</span> <i class="fa fa-fw pull-right fa-angle-down"></i></a>
|
<a href="#" data-toggle="collapse" data-target="#submenu-organisations" aria-expanded="false"><i class="fa fa-fw fa-sitemap"></i> <span>{{ translate("ORGANISATION.SELF") }}</span> <i class="fa fa-fw pull-right fa-angle-down"></i></a>
|
||||||
<ul id="submenu-organisations" class="collapsable collapse" aria-expanded="false" style="height: 1px;">
|
<ul id="submenu-organisations" class="collapsable collapse" aria-expanded="false" style="height: 1px;">
|
||||||
{% for organisation in current_user.organisations %}
|
{% for organisation in current_user.organisations %}
|
||||||
{% if (organisation.flag_approved and isOrganisationMember(organisation)) or isOrganisationRegistrant(organisation) %}
|
{% if organisation.flag_approved or isOrganisationRegistrant(organisation) %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{site.uri.public}}/organisations/o/{{organisation.slug}}"><i class="fas fa-angle-double-right"></i> <span>{{organisation.name}}</span></a>
|
<a href="{{site.uri.public}}/organisations/o/{{organisation.slug}}"><i class="fas fa-angle-double-right"></i> <span>{{organisation.name}}</span></a>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
<i class="fas fa-minus-square"></i> {{translate("VIEW_DELETED")}}
|
<i class="fas fa-minus-square"></i> {{translate("VIEW_DELETED")}}
|
||||||
</button>
|
</button>
|
||||||
{% elseif checkAccess('register_organisation') %}
|
{% elseif checkAccess('register_organisation') %}
|
||||||
{% if (organisationConfig.membership.single_membership == 0) or (current_user.organisations.count == 0) %}
|
{% if (organisationConfig.membership.single_membership == 0) or ((current_user.organisations.count == 0) and (current_user.pendingOrganisations.count == 0)) %}
|
||||||
<button type="button" class="btn btn-success js-organisation-register">
|
<button type="button" class="btn btn-success js-organisation-register">
|
||||||
<i class="fas fa-plus-square"></i> {{translate("ORGANISATION.REGISTRATION.REGISTER")}}
|
<i class="fas fa-plus-square"></i> {{translate("ORGANISATION.REGISTRATION.REGISTER")}}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -117,7 +117,7 @@
|
|||||||
{% endverbatim %}{{translate("LEAVE")}}{% verbatim %}
|
{% endverbatim %}{{translate("LEAVE")}}{% verbatim %}
|
||||||
</button>
|
</button>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
{% endverbatim %}{% if (organisationConfig.membership.single_membership == 0) or (current_user.organisations.count == 0) %}{% verbatim %}
|
{% endverbatim %}{% if (organisationConfig.membership.single_membership == 0) or ((current_user.organisations.count == 0) and (current_user.pendingOrganisations.count == 0)) %}{% verbatim %}
|
||||||
<button type="button" data-slug="{{row.slug}}" class="btn btn-success js-organisation-join" style="min-width: 70px">
|
<button type="button" data-slug="{{row.slug}}" class="btn btn-success js-organisation-join" style="min-width: 70px">
|
||||||
{% endverbatim %}{{translate("JOIN")}}{% verbatim %}
|
{% endverbatim %}{{translate("JOIN")}}{% verbatim %}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -83,15 +83,18 @@
|
|||||||
{% block table_cell_template_organisations %}
|
{% block table_cell_template_organisations %}
|
||||||
{% verbatim %}
|
{% verbatim %}
|
||||||
<script id="user-table-column-organisations" type="text/x-handlebars-template">
|
<script id="user-table-column-organisations" type="text/x-handlebars-template">
|
||||||
{{#if row.organisations.length }}
|
|
||||||
<td style="line-height: 2em;">
|
<td style="line-height: 2em;">
|
||||||
|
{{#if row.organisations.length }}
|
||||||
{{#each row.organisations }}
|
{{#each row.organisations }}
|
||||||
<a href="{% endverbatim %}{{site.uri.public}}{% verbatim %}/organisations/o/{{this.slug}}" class="label bg-primary {{#ifx this.pivot.flag_approved '!=' 1 }}membership-pending{{/ifx}} {{#ifx this.flag_approved '!=' 1 }}organisation-pending{{/ifx}} {{#if this.pivot.flag_admin }}organisation-admin{{/if}}" title="{{this.description}}" data-text="{{this.name}}" style="font-size: 100%;">{{this.name}}</a><br>
|
<a href="{% endverbatim %}{{site.uri.public}}{% verbatim %}/organisations/o/{{this.slug}}" class="label bg-primary {{#ifx this.flag_approved '!=' 1 }}organisation-pending{{/ifx}} {{#if this.pivot.flag_admin }}organisation-admin{{/if}}" title="{{this.description}}" data-text="{{this.name}}" style="font-size: 100%;">{{this.name}}</a><br>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</td>
|
|
||||||
{{ else }}
|
|
||||||
<td></td>
|
|
||||||
{{/if }}
|
{{/if }}
|
||||||
|
{{#if row.pending_organisations.length }}
|
||||||
|
{{#each row.pending_organisations }}
|
||||||
|
<a href="{% endverbatim %}{{site.uri.public}}{% verbatim %}/organisations/o/{{this.slug}}" class="label bg-primary {{#ifx this.flag_approved '!=' 1 }}organisation-pending{{/ifx}} {{#if this.pivot.flag_admin }}organisation-admin{{/if}} membership-pending" title="{{this.description}}" data-text="{{this.name}}" style="font-size: 100%;">{{this.name}}</a><br>
|
||||||
|
{{/each}}
|
||||||
|
{{/if }}
|
||||||
|
</td>
|
||||||
</script>
|
</script>
|
||||||
{% endverbatim %}
|
{% endverbatim %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user