Skip to content

Commit d0917d7

Browse files
Return only assigned projects to team users (ActiveLearningStudio#203)
1 parent 38641b9 commit d0917d7

File tree

8 files changed

+258
-28
lines changed

8 files changed

+258
-28
lines changed

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
4848
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
4949

5050
MATTERMOST_SERVER=default
51+
MATTERMOST_AUTH=default
5152
MATTERMOST_HOST=
5253
MATTERMOST_LOGIN=
5354
MATTERMOST_PASSWORD=
55+
MATTERMOST_TOKEN=
5456
MATTERMOST_DEFAULT_TEAM_ID=
5557

5658
GAPI_CLASSROOM_CREDENTIALS=

app/Http/Controllers/Api/V1/ActivityController.php

-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ public function detail(Activity $activity)
324324
$data = ['h5p_parameters' => null, 'user_name' => null, 'user_id' => null];
325325

326326
if ($activity->playlist->project->user) {
327-
// TODO: is this correct?
328327
$data['user_name'] = $activity->playlist->project->user;
329328
$data['user_id'] = $activity->playlist->project->id;
330329
}

app/Http/Controllers/Api/V1/UserController.php

-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public function getUsersForTeam(UserSearchRequest $userSearchRequest)
8383
*/
8484
public function store(Request $request)
8585
{
86-
// TODO: do we need user create functionality for admin ?
8786
return response([
8887
'errors' => ['Forbidden. Please use register to create new user.'],
8988
], 403);

app/Repositories/Team/TeamRepository.php

+32-15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use App\Repositories\Team\TeamRepositoryInterface;
1313
use App\Repositories\User\UserRepositoryInterface;
1414
use App\User;
15+
use Gnello\Mattermost\Laravel\Facades\Mattermost;
1516
use Illuminate\Support\Collection;
1617
use Illuminate\Support\Facades\DB;
1718
use Illuminate\Support\Facades\Hash;
@@ -23,6 +24,7 @@ class TeamRepository extends BaseRepository implements TeamRepositoryInterface
2324
private $userRepository;
2425
private $projectRepository;
2526
private $invitedTeamUserRepository;
27+
private $matDriver;
2628

2729
/**
2830
* TeamRepository constructor.
@@ -44,6 +46,8 @@ public function __construct(
4446
$this->userRepository = $userRepository;
4547
$this->projectRepository = $projectRepository;
4648
$this->invitedTeamUserRepository = $invitedTeamUserRepository;
49+
50+
$this->matDriver = Mattermost::server('default');
4751
}
4852

4953
/**
@@ -293,31 +297,44 @@ public function removeMemberFromTeamProject($team, $project, $user)
293297
*/
294298
public function getTeamDetail($teamId)
295299
{
300+
$authenticated_user = auth()->user();
296301
$team = $this->model->find($teamId);
297302

298303
if ($team) {
304+
$team_projects = [];
299305
foreach ($team->projects as $team_project) {
300-
$team_project_users = DB::table('team_project_user')
306+
$tpu = DB::table('team_project_user')
301307
->where('team_id', $team->id)
302308
->where('project_id', $team_project->id)
303-
->get();
304-
305-
$project_users = [];
306-
foreach ($team_project_users as $team_project_user) {
307-
$user = User::find($team_project_user->user_id);
308-
if ($user) {
309-
$project_users[] = [
310-
'id' => $user->id,
311-
'first_name' => $user->first_name,
312-
'last_name' => $user->last_name,
313-
'email' => $user->email,
314-
];
309+
->where('user_id', $authenticated_user->id)
310+
->first();
311+
312+
if ($tpu) {
313+
$team_project_users = DB::table('team_project_user')
314+
->where('team_id', $team->id)
315+
->where('project_id', $team_project->id)
316+
->get();
317+
318+
$project_users = [];
319+
foreach ($team_project_users as $team_project_user) {
320+
$user = User::find($team_project_user->user_id);
321+
if ($user) {
322+
$project_users[] = [
323+
'id' => $user->id,
324+
'first_name' => $user->first_name,
325+
'last_name' => $user->last_name,
326+
'email' => $user->email,
327+
];
328+
}
315329
}
316-
}
317330

318-
$team_project->users = $project_users;
331+
$team_project->users = $project_users;
332+
$team_projects[] = $team_project;
333+
}
319334
}
320335

336+
$team->projects = $team_projects;
337+
321338
foreach ($team->users as $team_user) {
322339
$team_project_users = DB::table('team_project_user')
323340
->where('team_id', $team->id)

app/Services/GoogleClassroom.php

+11-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
class GoogleClassroom implements GoogleClassroomInterface
1818
{
1919
/**
20-
* Google Classroom Serivce object
20+
* Google Classroom Service object
2121
*
2222
* @var \Google_Service_Classroom
2323
*/
@@ -32,7 +32,8 @@ class GoogleClassroom implements GoogleClassroomInterface
3232

3333
/**
3434
* Creates an instance of the class
35-
*
35+
*
36+
* @param $accessTokenStr
3637
*
3738
* @return void
3839
*/
@@ -105,7 +106,7 @@ public function getClient()
105106

106107
/**
107108
* Set GcClasswork repository object
108-
*
109+
*
109110
* @param GcClassworkRepositoryInterface $gcClassworkRepository
110111
*
111112
* @return void
@@ -324,7 +325,7 @@ public function createProjectAsCourse(Project $project, $courseId = null)
324325

325326
// We need to save the classwork id in the database, and also need to retrieve it later.
326327
// So we make a dummy insertion in the database, and append the id in the link.
327-
// We have to do this way because, we cannot update the 'Materials' link for classwork
328+
// We have to do this way because, we cannot update the 'Materials' link for classwork
328329
$classworkItem = $this->gc_classwork->create([
329330
'classwork_id' => uniqid(),
330331
'path' => $activityLink,
@@ -334,7 +335,7 @@ public function createProjectAsCourse(Project $project, $courseId = null)
334335
if ($classworkItem) {
335336
// Now, we append the activity link with our database id.
336337
$activityLink .= '/' . $classworkItem->id;
337-
338+
338339
$courseWorkData = [
339340
'course_id' => $course->id,
340341
'topic_id' => $topic->topicId,
@@ -343,13 +344,13 @@ public function createProjectAsCourse(Project $project, $courseId = null)
343344
'activity_link' => $frontURL . $activityLink
344345
];
345346
$courseWork = $this->createCourseWork($courseWorkData);
346-
347+
347348
// Once coursework id is generated, we'll update that in our database.
348349
$this->gc_classwork->update([
349350
'classwork_id' => $courseWork->id,
350351
'path' => $activityLink
351352
], $classworkItem->id);
352-
353+
353354
$return['topics'][$count]['course_work'][] = GCCourseWorkResource::make($courseWork)->resolve();
354355
}
355356
}
@@ -384,7 +385,7 @@ public function getFirstStudentSubmission($courseId, $classworkId, $userId = "me
384385
$submissions = $this->getStudentSubmissions($courseId, $classworkId, $userId);
385386
// Grab the first submission
386387
$first = $submissions[0];
387-
388+
388389
return $first;
389390
}
390391

@@ -444,7 +445,7 @@ public function turnIn($courseId, $courseWorkId, $id)
444445
{
445446
$studentSubmissions = $this->service->courses_courseWork_studentSubmissions;
446447
$requestBody = new \Google_Service_Classroom_TurnInStudentSubmissionRequest;
447-
return $studentSubmissions->turnIn($courseId, $courseWorkId, $id, $requestBody);
448+
return $studentSubmissions->turnIn($courseId, $courseWorkId, $id, $requestBody);
448449
}
449450

450451
/**
@@ -505,7 +506,7 @@ public function isAssignmentSubmitted($state)
505506
$submittedStates = [self::ASSIGNMENT_STATE_TURNED_IN, self::ASSIGNMENT_STATE_RETURNED];
506507
return (in_array($state, $submittedStates) ? true : false);
507508
}
508-
509+
509510
/**
510511
* Determine front URL of the application.
511512
*

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"doctrine/dbal": "^2.10",
1616
"fideloper/proxy": "^4.2",
1717
"fruitcake/laravel-cors": "^1.0",
18+
"gnello/laravel-mattermost-driver": "^1.2",
1819
"google/apiclient": "^2.7",
1920
"guzzlehttp/guzzle": "^6.3",
2021
"h5p/h5p-core": "^1.24",

composer.lock

+152-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)