Skip to content

Commit 7129591

Browse files
authored
Merge pull request #53 from udzuki/feat-25-caliper-lti-alternatename
feat: LTI連携のログで機関のスコープをalternatenameから取得(Caliperステートメント変換)
2 parents bf55daf + 4cb6619 commit 7129591

25 files changed

Lines changed: 261 additions & 54 deletions

caliper/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM composer:1.9 AS builder
22

3-
LABEL version="2.3.0"
3+
LABEL version="2.4.0"
44

55
WORKDIR /stage
66
COPY . .

caliper/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#### Common definitions
55
- agent.id = <MOODLE_URL>/user/profile.php?id=<mdl_logstore_standard_log.userid>
66
- agent.name = <mdl_user.username> (Converted to SHA256 hash)
7+
※ Set to <mdl_user.alternatename> instead if `DB_EPPN` is enabled and <mdl_user.auth> is 'lti'
78
- agent.description = <mdl_user.description>
89
- agent.type = Person
910
- eventTime = <mdl_logstore_standard_log.timecreated>(Converted)
@@ -372,6 +373,7 @@
372373
#### Common definitions
373374
- agent.id = <MOODLE_URL>/user/profile.php?id=<mdl_mdl_scorm_scoes_track.userid>
374375
- agent.name = <mdl_user.username> (Converted to SHA256 hash)
376+
※ Set to <mdl_user.alternatename> instead if `DB_EPPN` is enabled and <mdl_user.auth> is 'lti'
375377
- agent.description = <mdl_user.description>
376378
- agent.type = Person
377379
- eventTime = <mdl_scorm_scoes_track.timemodified>(Converted)

caliper/app/Caliper/Traits/Util.php

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,22 @@ protected function getUser(string $id): ?User
3131
}
3232
}
3333

34-
public function getAnonymizedUsername(string $username): string
34+
public function getUsername(User $actor): ?string
3535
{
36-
$hash = hash('sha256', $username);
37-
$eppnValue = env('DB_EPPN');
38-
if (is_bool($eppnValue) && $eppnValue) {
39-
$enableEppn = true;
40-
} elseif (is_string($eppnValue) && $eppnValue == 'true') {
41-
$enableEppn = true;
36+
if ($this->isEnabledEppn()) {
37+
return ($actor->auth === 'lti')
38+
? $actor->alternatename
39+
: $actor->username;
4240
} else {
43-
$enableEppn = false;
41+
return $actor->username;
4442
}
45-
if ($enableEppn) {
43+
}
44+
45+
public function getAnonymizedUsername(User $actor): string
46+
{
47+
if ($this->isEnabledEppn()) {
48+
$username = $this->getUsername($actor);
49+
$hash = $username ? hash('sha256', $username) : '';
4650
$eppn = Eppn::where('username', $username)->first();
4751
if (is_null($eppn)) {
4852
if (strpos($username, '@')) {
@@ -62,7 +66,7 @@ public function getAnonymizedUsername(string $username): string
6266
return $eppn->hash;
6367
}
6468
} else {
65-
return $hash;
69+
return hash('sha256', $actor->username);
6670
}
6771
}
6872

@@ -122,4 +126,16 @@ public function getCourseId(string $id): string
122126
{
123127
return env('APP_URL') . '/course/view.php?id=' . $id;
124128
}
129+
130+
protected function isEnabledEppn(): bool
131+
{
132+
$eppnValue = env('DB_EPPN');
133+
if (is_bool($eppnValue) && $eppnValue) {
134+
return true;
135+
} elseif (is_string($eppnValue) && $eppnValue == 'true') {
136+
return true;
137+
} else {
138+
return false;
139+
}
140+
}
125141
}

caliper/app/Models/Moodle/User.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ public function scopeColumn($query)
152152
{
153153
return $query->select([
154154
'id',
155+
'auth',
155156
'username',
156-
'description'
157+
'description',
158+
'alternatename'
157159
]);
158160
}
159161
}

caliper/app/Profiles/AssessableSubmitted.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ public function __construct(AppAssessableSubmitted $as)
2929
$objectId = $as->getObjectId();
3030
$partOfId = $as->getCourseId($partOf->id);
3131

32-
$this->originalUsername = $actor->username;
32+
$this->originalUsername = $as->getUsername($actor);
3333

3434
$this
3535
->setAction(new Action(Action::SUBMITTED))
3636
->setEventTime($as->getEventTime())
3737
->setActor(
3838
(new Person((string) $actorId))
39-
->setName($as->getAnonymizedUsername($actor->username))
39+
->setName($as->getAnonymizedUsername($actor))
4040
->setDescription($actor->description ?? '')
4141
)
4242
->setObject(

caliper/app/Profiles/AttemptStarted.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public function __construct(AppAttemptStarted $as)
3232
$partOfId = $as->getCourseId($partOf->id);
3333
$generatedId = $as->getGeneratedId();
3434

35-
$this->originalUsername = $actor->username;
35+
$this->originalUsername = $as->getUsername($actor);
3636

3737
$this
3838
->setAction(new Action(Action::STARTED))
3939
->setActor(
4040
(new Person((string) $actorId))
41-
->setName($as->getAnonymizedUsername($actor->username))
41+
->setName($as->getAnonymizedUsername($actor))
4242
->setDescription($actor->description ?? '')
4343
)
4444
->setObject(

caliper/app/Profiles/AttemptSubmitted.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public function __construct(AppAttemptSubmitted $as)
3232
$partOfId = $as->getCourseId($partOf->id);
3333
$generatedId = $as->getGeneratedId();
3434

35-
$this->originalUsername = $actor->username;
35+
$this->originalUsername = $as->getUsername($actor);
3636

3737
$this
3838
->setAction(new Action(Action::SUBMITTED))
3939
->setActor(
4040
(new Person((string) $actorId))
41-
->setName($as->getAnonymizedUsername($actor->username))
41+
->setName($as->getAnonymizedUsername($actor))
4242
->setDescription($actor->description ?? '')
4343
)
4444
->setObject(

caliper/app/Profiles/CmiCoreTotalTime.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ public function __construct(AppCmiCoreTotalTime $cctt)
2929
$objectId = $cctt->getObjectId();
3030
$generatedId = $cctt->getGeneratedId();
3131

32-
$this->originalUsername = $actor->username;
32+
$this->originalUsername = $cctt->getUsername($actor);
3333

3434
$this
3535
->setAction(new Action(Action::SUBMITTED))
3636
->setActor(
3737
(new Person((string) $actorId))
38-
->setName($cctt->getAnonymizedUsername($actor->username))
38+
->setName($cctt->getAnonymizedUsername($actor))
3939
->setDescription($actor->description ?? '')
4040
)
4141
->setObject(

caliper/app/Profiles/CourseModuleViewed.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ public function __construct(AppCourseModuleViewed $cmv)
3030
$objectId = $cmv->getObjectId();
3131
$partOfId = $cmv->getCourseId($partOf->id);
3232

33-
$this->originalUsername = $actor->username;
33+
$this->originalUsername = $cmv->getUsername($actor);
3434

3535
$this
3636
->setAction(new Action(Action::NAVIGATED_TO))
3737
->setActor(
3838
(new Person((string) $actorId))
39-
->setName($cmv->getAnonymizedUsername($actor->username))
39+
->setName($cmv->getAnonymizedUsername($actor))
4040
->setDescription($actor->description ?? '')
4141
)
4242
->setObject(

caliper/app/Profiles/CourseViewed.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public function __construct(AppCourseViewed $cv)
2626
$actorId = $cv->getUserId($actor->id);
2727
$objectId = $cv->getCourseId($object->id);
2828

29-
$this->originalUsername = $actor->username;
29+
$this->originalUsername = $cv->getUsername($actor);
3030

3131
$this
3232
->setAction(new Action(Action::VIEWED))
3333
->setActor(
3434
(new Person((string) $actorId))
35-
->setName($cv->getAnonymizedUsername($actor->username))
35+
->setName($cv->getAnonymizedUsername($actor))
3636
->setDescription($actor->description ?? '')
3737
)
3838
->setObject(

0 commit comments

Comments
 (0)