-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add completion condition testing and event monitoring to the playground * Update all modules and fix service creation bug * Reference modules on github only * Clean Vue components and add ability to control user/group/role combination * Update tests and increase coverage * Update docs * Update changelog
- Loading branch information
1 parent
6143241
commit 276bb14
Showing
234 changed files
with
193,725 additions
and
1,175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace BristolSU\Playground\Http\Controllers\Api; | ||
|
||
use BristolSU\Playground\Http\Controllers\Controller; | ||
use BristolSU\Support\Events\Contracts\EventRepository; | ||
use BristolSU\Support\Module\Module; | ||
|
||
class ModuleEventController extends Controller | ||
{ | ||
|
||
public function index(Module $module, EventRepository $eventRepository) | ||
{ | ||
return $eventRepository->allForModule($module->getAlias()); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
app/Http/Controllers/Api/ModuleInstanceCompletionConditionController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace BristolSU\Playground\Http\Controllers\Api; | ||
|
||
use BristolSU\Playground\Http\Controllers\Controller; | ||
use BristolSU\Support\ActivityInstance\Contracts\ActivityInstanceResolver; | ||
use BristolSU\Support\Completion\Contracts\CompletionConditionInstanceRepository; | ||
use BristolSU\Support\Completion\Contracts\CompletionConditionTester; | ||
use BristolSU\Support\ModuleInstance\ModuleInstance; | ||
use Illuminate\Http\Request; | ||
|
||
/** | ||
* Handle completion conditions | ||
*/ | ||
class ModuleInstanceCompletionConditionController extends Controller | ||
{ | ||
|
||
public function store(ModuleInstance $moduleInstance, Request $request, CompletionConditionInstanceRepository $conditionInstanceRepository) | ||
{ | ||
$completion = $conditionInstanceRepository->create([ | ||
'alias' => $request->input('alias'), | ||
'name' => 'CC For ' . $moduleInstance->name, | ||
'description' => 'Completion Condition in the Playground', | ||
'settings' => $request->input('settings') | ||
]); | ||
$moduleInstance->completion_condition_instance_id = $completion->id; | ||
$moduleInstance->save(); | ||
return $completion; | ||
} | ||
|
||
public function test(ModuleInstance $moduleInstance, CompletionConditionTester $tester, ActivityInstanceResolver $activityInstanceResolver) | ||
{ | ||
if($moduleInstance->completion_condition_instance_id === null) { | ||
return abort(404, 'Could not find the completion condition'); | ||
} | ||
$activityInstance = $activityInstanceResolver->getActivityInstance(); | ||
return [ | ||
'result' => $tester->evaluate($activityInstance, $moduleInstance->completionConditionInstance), | ||
'percentage' => $tester->evaluatePercentage($activityInstance, $moduleInstance->completionConditionInstance) | ||
]; | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
app/Http/Controllers/Api/ModuleInstanceEventController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace BristolSU\Playground\Http\Controllers\Api; | ||
|
||
use BristolSU\Playground\Http\Controllers\Controller; | ||
use BristolSU\Playground\Support\Events\Event; | ||
use BristolSU\Support\ModuleInstance\ModuleInstance; | ||
|
||
class ModuleInstanceEventController extends Controller | ||
{ | ||
|
||
public function index(ModuleInstance $moduleInstance) | ||
{ | ||
return Event::where('module_instance_id', $moduleInstance->id())->get(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,20 @@ | |
|
||
namespace BristolSU\Playground\Support\Authentication; | ||
|
||
use BristolSU\ControlDB\Contracts\Repositories\DataGroup; | ||
use BristolSU\ControlDB\Contracts\Repositories\DataPosition; | ||
use BristolSU\ControlDB\Contracts\Repositories\DataRole; | ||
use BristolSU\ControlDB\Contracts\Repositories\Pivots\UserGroup; | ||
use BristolSU\ControlDB\Contracts\Repositories\Pivots\UserRole; | ||
use BristolSU\Support\Activity\Activity; | ||
use BristolSU\Support\Authentication\Contracts\Authentication as AuthenticationContract; | ||
use BristolSU\Support\User\Contracts\UserAuthentication; | ||
use BristolSU\ControlDB\Contracts\Models\Group; | ||
use BristolSU\ControlDB\Contracts\Models\Role; | ||
use BristolSU\ControlDB\Contracts\Models\User; | ||
use BristolSU\ControlDB\Contracts\Repositories\User as UserRepository; | ||
use Illuminate\Contracts\Auth\Factory as AuthFactory; | ||
use Illuminate\Support\Facades\Request; | ||
use Illuminate\Support\Str; | ||
|
||
/** | ||
* Authentication contract that uses the database user | ||
|
@@ -72,10 +79,17 @@ public function setUser(User $user) | |
* | ||
* This function does not provide a way to get groups | ||
* | ||
* @return null | ||
* @return Group|null | ||
*/ | ||
public function getGroup() | ||
{ | ||
if($this->activity()->exists) { | ||
if($this->activity()->activity_for === 'group') { | ||
return $this->getGroupForUser(); | ||
} elseif($this->activity()->activity_for === 'role') { | ||
return $this->getRole()->group(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
|
@@ -84,10 +98,13 @@ public function getGroup() | |
* | ||
* This function does not provide a way to get roles | ||
* | ||
* @return null | ||
* @return Role|null | ||
*/ | ||
public function getRole() | ||
{ | ||
if($this->activity()->exists && $this->activity()->activity_for === 'role') { | ||
return $this->getRoleForUser(); | ||
} | ||
return null; | ||
} | ||
|
||
|
@@ -127,4 +144,68 @@ public function setRole(Role $role) | |
public function reset(): void | ||
{ | ||
} | ||
|
||
protected function activity(): Activity | ||
{ | ||
if(Request::route() && Request::route()->hasParameter('activity_slug')) { | ||
return Request::route()->parameter('activity_slug'); | ||
} | ||
return app(Activity::class); | ||
} | ||
|
||
/** | ||
* Find or create a group the user is a member of | ||
* | ||
* @return Group | ||
*/ | ||
protected function getGroupForUser(): Group { | ||
$userGroupRepository = app(UserGroup::class); | ||
$dataGroupRepository = app(DataGroup::class); | ||
$groupRepository = app(\BristolSU\ControlDB\Contracts\Repositories\Group::class); | ||
|
||
$groups = $userGroupRepository->getGroupsThroughUser($this->getUser()); | ||
if($groups->count() > 0) { | ||
return $groups->first(); | ||
} | ||
|
||
$dataGroup = $dataGroupRepository->create('Group ' . Str::random(), ($this->getUser()->data()->email() ?? '[email protected]')); | ||
$group = $groupRepository->create($dataGroup->id()); | ||
|
||
$userGroupRepository->addUserToGroup($this->getUser(), $group); | ||
return $group; | ||
} | ||
|
||
/** | ||
* Find or create a role the user is in | ||
* | ||
* @return Role | ||
*/ | ||
protected function getRoleForUser(): Role { | ||
$userRoleRepository = app(UserRole::class); | ||
$dataRoleRepository = app(DataRole::class); | ||
$roleRepository = app(\BristolSU\ControlDB\Contracts\Repositories\Role::class); | ||
$dataGroupRepository = app(DataGroup::class); | ||
$groupRepository = app(\BristolSU\ControlDB\Contracts\Repositories\Group::class); | ||
$dataPositionRepository = app(DataPosition::class); | ||
$positionRepository = app(\BristolSU\ControlDB\Contracts\Repositories\Position::class); | ||
|
||
$roles = $userRoleRepository->getRolesThroughUser($this->getUser()); | ||
if($roles->count() > 0) { | ||
return $roles->first(); | ||
} | ||
|
||
$dataRole = $dataRoleRepository->create('Role ' . Str::random(), ($this->getUser()->data()->email() ?? '[email protected]')); | ||
|
||
$dataGroup = $dataGroupRepository->create('Group ' . Str::random(), ($this->getUser()->data()->email() ?? '[email protected]')); | ||
$group = $groupRepository->create($dataGroup->id()); | ||
|
||
$dataPosition = $dataPositionRepository->create('Position ' . Str::random(), 'Position ' . Str::random()); | ||
$position = $positionRepository->create($dataPosition->id()); | ||
|
||
$role = $roleRepository->create($position->id(), $group->id(), $dataRole->id()); | ||
|
||
$userRoleRepository->addUserToRole($this->getUser(), $role); | ||
|
||
return $role; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.