Skip to content

Commit f6a9cd3

Browse files
committed
[XSD-294] Adding getUserAsAdmin method to expose user activity
1 parent 16ddc68 commit f6a9cd3

File tree

6 files changed

+30
-0
lines changed

6 files changed

+30
-0
lines changed

src/Contracts/GitPlatformInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public function getUserList($onlyActive = true): array;
3131

3232
public function getUser(string $idOrName): GitUserInterface;
3333

34+
public function getUserAsAdmin(string $idOrName): GitUserInterface;
35+
3436
public function addUser(array $properties): GitUserInterface;
3537

3638
public function getCurrentUser(): GitUserInterface;

src/Contracts/GitUserInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* @property-read string $username
77
* @property-read string $email
88
* @property-read string $created_at
9+
* @property-read string $last_sign_in_at
10+
* @property-read string $last_activity_on
911
*/
1012
interface GitUserInterface extends GitOwnerInterface
1113
{

src/Models/GitLab/GitLabPlatform.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ public function getUser(string $idOrName): GitUserInterface
143143
return $this->client->getModelInstance(GitLabClient::TYPE_USERS, $idOrName, $this);
144144
}
145145

146+
public function getUserAsAdmin(string $idOrName): GitUserInterface
147+
{
148+
$this->client->sudo(data_get($this->client->users()->me(), 'id'));
149+
try {
150+
return $this->client->getModelInstance(GitLabClient::TYPE_USERS, $idOrName, $this);
151+
} finally {
152+
$this->client->sudo(null);
153+
}
154+
}
155+
146156
public function addUser(array $properties): GitUserInterface
147157
{
148158
GitLabUser::validateAdd($properties);

src/Models/GitUser.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ abstract class GitUser extends AbstractGitModel implements GitUserInterface
1818
'email',
1919
'description',
2020
'created_at',
21+
'last_sign_in_at',
22+
'last_activity_on',
2123
];
24+
2225
/**
2326
* @var bool[]
2427
*/
@@ -28,6 +31,7 @@ abstract class GitUser extends AbstractGitModel implements GitUserInterface
2831
'email' => true,
2932
'description' => false,
3033
];
34+
3135
/**
3236
* @var GitPlatformInterface|GitPlatform
3337
*/

src/Models/Gitea/GiteaPlatform.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ public function getUser(string $idOrName): GitUserInterface
6969
}
7070
}
7171

72+
public function getUserAsAdmin(string $idOrName): GitUserInterface
73+
{
74+
if (is_numeric($idOrName)) {
75+
return $this->client->getFirst(GiteaUser::class, "/users/search?uid={$idOrName}", $this);
76+
} else {
77+
return $this->client->get(GiteaUser::class, "/users/{$idOrName}", $this);
78+
}
79+
}
80+
7281
public function addUser(array $properties): GitUserInterface
7382
{
7483
return $this->client->post(GiteaUser::class, "/admin/users", $this, $properties);

src/Models/Gitea/GiteaUser.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ protected function mapProperties(array $properties)
1717
{
1818
$properties['name'] = $properties['full_name'] ?: $properties['login'];
1919
$properties['username'] = $properties['login'];
20+
$properties['last_sign_in_at'] = $properties['last_login'];
21+
$properties['last_activity_on'] = $properties['last_login'];
22+
2023
return $properties;
2124
}
2225

0 commit comments

Comments
 (0)