Added an approved flag to organisations with a status column as an indicator, pending registration/approval workflow
This commit is contained in:
@@ -78,4 +78,7 @@ return [
|
||||
'SLUG_NOT_IN_USE' => 'A <strong>{{slug}}</strong> slug does not exist',
|
||||
|
||||
'LEAVE_CANNOT_UNDONE' => 'This action cannot be undone.',
|
||||
|
||||
'APPROVED' => 'Approved',
|
||||
'PENDING' => 'Pending',
|
||||
];
|
||||
|
||||
@@ -101,8 +101,7 @@ class OrganisationController extends SimpleController
|
||||
return $response->withJson([], 400);
|
||||
}
|
||||
|
||||
/** @var \UserFrosting\Support\Repository\Repository $config */
|
||||
$config = $this->ci->config;
|
||||
$data['flag_approved'] = 1;
|
||||
|
||||
// All checks passed! log events/activities and create organisation
|
||||
// Begin transaction - DB will be rolled back if an exception occurs
|
||||
@@ -621,7 +620,7 @@ class OrganisationController extends SimpleController
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renders the modal form for editing an existing organisation.
|
||||
*
|
||||
|
||||
55
src/Database/Migrations/v002/UpdateOrganisationsTable.php
Normal file
55
src/Database/Migrations/v002/UpdateOrganisationsTable.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* AVSDev UF Organisations (https://avsdev.uk)
|
||||
*
|
||||
* @link https://git.avsdev.uk/avsdev/sprinkle-organisations
|
||||
* @license https://git.avsdev.uk/avsdev/sprinkle-organisations/blob/master/LICENSE.md (LGPL-3.0 License)
|
||||
*/
|
||||
|
||||
namespace UserFrosting\Sprinkle\Organisations\Database\Migrations\v002;
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use UserFrosting\Sprinkle\Organisations\Database\Models\Organisation;
|
||||
use UserFrosting\Sprinkle\Core\Database\Migration;
|
||||
use UserFrosting\Sprinkle\Core\Facades\Seeder;
|
||||
|
||||
/**
|
||||
* Organisations table migration
|
||||
* Adds a `flag_verified` column to the `organisations` table
|
||||
* Version 1.0.0.
|
||||
*
|
||||
* @author Craig Williams (https://avsdev.uk)
|
||||
*/
|
||||
class UpdateOrganisationsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $dependencies = [
|
||||
'\UserFrosting\Sprinkle\Account\Database\Migrations\v400\UsersTable',
|
||||
'\UserFrosting\Sprinkle\Organisations\Database\Migrations\v001\OrganisationsTable',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if ($this->schema->hasTable('organisations')) {
|
||||
$this->schema->table('organisations', function (Blueprint $table) {
|
||||
$table->boolean('flag_approved')->default(1)->comment('Set to 1 if the organisation has been approved, 0 otherwise.');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$this->schema->table('organisations', function (Blueprint $table) {
|
||||
$table->dropColumn('flag_verified');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ class Organisation extends Model implements OrganisationInterface
|
||||
'slug',
|
||||
'name',
|
||||
'description',
|
||||
'flag_approved',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace UserFrosting\Sprinkle\Organisations\Sprunje;
|
||||
|
||||
use UserFrosting\Sprinkle\Core\Sprunje\Sprunje;
|
||||
use UserFrosting\Sprinkle\Core\Facades\Translator;
|
||||
|
||||
/**
|
||||
* OrganisationSprunje.
|
||||
@@ -22,18 +23,24 @@ class OrganisationSprunje extends Sprunje
|
||||
{
|
||||
protected $name = 'organisations';
|
||||
|
||||
protected $listable = [
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $sortable = [
|
||||
'name',
|
||||
'description',
|
||||
'member_count',
|
||||
'admin_count'
|
||||
'admin_count',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $filterable = [
|
||||
'name',
|
||||
'description',
|
||||
'member_count',
|
||||
'admin_count'
|
||||
'admin_count',
|
||||
'status',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -43,4 +50,63 @@ class OrganisationSprunje extends Sprunje
|
||||
{
|
||||
return $this->classMapper->createInstance('organisation')->newQuery()->joinMemberCounts();
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter by status (approved, pending).
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected function filterStatus($query, $value)
|
||||
{
|
||||
// Split value on separator for OR queries
|
||||
$values = explode($this->orSeparator, $value);
|
||||
$query->where(function ($query) use ($values) {
|
||||
foreach ($values as $value) {
|
||||
if ($value == 'approved') {
|
||||
$query->orWhere('flag_approved', 1);
|
||||
} elseif ($value == 'pending') {
|
||||
$query->orWhere('flag_approved', 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of possible user statuses.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function listStatus()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'value' => 'approved',
|
||||
'text' => Translator::translate('APPROVED'),
|
||||
],
|
||||
[
|
||||
'value' => 'pending',
|
||||
'text' => Translator::translate('PENDING'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort approved, pending
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param string $direction
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected function sortStatus($query, $direction)
|
||||
{
|
||||
$query->orderBy('flag_approved', ($direction === 'desc' ? 'asc' : 'desc'));
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<tr>
|
||||
<th class="sorter-metatext" data-column-name="name" data-column-template="#organisation-table-column-info" data-priority="1">{{translate('ORGANISATION')}} <i class="fas fa-sort"></i></th>
|
||||
<th class="sorter-metatext" data-column-name="description" data-column-template="#organisation-table-column-description" data-priority="2">{{translate("DESCRIPTION")}} <i class="fas fa-sort"></i></th>
|
||||
<th class="filter-select filter-metatext" data-column-name="status" data-column-template="#user-table-column-status" data-priority="2">{{translate("STATUS")}} <i class="fas fa-sort"></i></th>
|
||||
<th class="sorter-metanum" data-column-name="member_count" data-column-template="#organisation-table-column-memberCount" data-priority="2">{{translate("ORGANISATION.MEMBER_COUNT")}} <i class="fas fa-sort"></i></th>
|
||||
<th class="sorter-metanum" data-column-name="admin_count" data-column-template="#organisation-table-column-adminCount" data-priority="2">{{translate("ORGANISATION.ADMIN_COUNT")}} <i class="fas fa-sort"></i></th>
|
||||
<th data-column-template="#organisation-table-column-actions" data-sorter="false" data-filter="false" data-priority="1">{{translate("ACTIONS")}}</th>
|
||||
@@ -45,6 +46,26 @@
|
||||
</td>
|
||||
</script>
|
||||
|
||||
<script id="user-table-column-status" type="text/x-handlebars-template">
|
||||
<td
|
||||
{{#ifx row.flag_approved '==' 1 }}
|
||||
data-text="approved"
|
||||
{{ else }}
|
||||
data-text="pending"
|
||||
{{/ifx }}
|
||||
>
|
||||
{{#ifx row.flag_approved '==' 1 }}
|
||||
<span>
|
||||
{% endverbatim %}{{translate("APPROVED")}}{% verbatim %}
|
||||
</span>
|
||||
{{ else }}
|
||||
<span class="text-danger">
|
||||
{% endverbatim %}{{translate("PENDING")}}{% verbatim %}
|
||||
</span>
|
||||
{{/ifx }}
|
||||
</td>
|
||||
</script>
|
||||
|
||||
<script id="organisation-table-column-memberCount" type="text/x-handlebars-template">
|
||||
<td>
|
||||
{{row.member_count}}
|
||||
|
||||
Reference in New Issue
Block a user