-
Notifications
You must be signed in to change notification settings - Fork 730
/
Copy pathUser.php
147 lines (131 loc) · 3.2 KB
/
User.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
namespace App;
use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasApiTokens, Notifiable;
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'last_alert_received_at' => 'datetime',
];
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'api_token',
'meta',
'password',
'private_key',
'public_worker_key',
'private_worker_key',
'provider_key_id',
'remember_token',
];
/**
* Get all of the server providers owned by the user.
*/
public function serverProviders()
{
return $this->hasMany(ServerProvider::class);
}
/**
* Get all of the source control providers owned by the user.
*/
public function sourceProviders()
{
return $this->hasMany(SourceProvider::class);
}
/**
* Get all of the storage providers owned by the user.
*/
public function storageProviders()
{
return $this->hasMany(StorageProvider::class);
}
/**
* All of the projects that belong to the user.
*/
public function projects()
{
return $this->hasMany(Project::class);
}
/**
* All of the projects that have been shared with the user.
*/
public function teamProjects()
{
return $this->belongsToMany(
Project::class, 'project_users', 'user_id', 'project_id'
)->using(Collaborator::class);
}
/**
* Determine if the user has access to the given project.
*
* @param Project $project
* @return bool
*/
public function canAccessProject($project)
{
return $this->projects->contains($project) ||
$this->teamProjects->contains($project);
}
/**
* Set the SSH key attributes on the model.
*
* @param object $value
* @return void
*/
public function setKeypairAttribute($value)
{
$this->attributes = [
'public_key' => $value->publicKey,
'private_key' => $value->privateKey,
] + $this->attributes;
}
/**
* Set the SSH key attributes on the model.
*
* @param object $value
* @return void
*/
public function setWorkerKeypairAttribute($value)
{
$this->attributes = [
'public_worker_key' => $value->publicKey,
'private_worker_key' => $value->privateKey,
] + $this->attributes;
}
/**
* Revoke API tokens with the given name.
*
* @param string $name
* @return void
*/
public function revokeTokens($name)
{
$this->tokens()->where('name', $name)->update(['revoked' => true]);
}
/**
* Get the path to the user's worker SSH key.
*
* @return string
*/
public function keyPath()
{
return SecureShellKey::storeFor($this);
}
}