1
1
<?php
2
2
3
-
4
3
namespace Authing \Mgmt ;
5
4
6
5
use Authing \Types \ChildrenNodesParam ;
9
8
use Authing \Types \DeleteNodeParam ;
10
9
use Authing \Types \DeleteOrgParam ;
11
10
use Authing \Types \IsRootNodeParam ;
11
+ use Authing \Types \ListNodeByIdAuthorizedResourcesParam ;
12
12
use Authing \Types \MoveNodeParam ;
13
13
use Authing \Types \Node ;
14
+ use Authing \Types \NodeByIdParam ;
14
15
use Authing \Types \NodeByIdWithMembersParam ;
15
16
use Authing \Types \Org ;
16
17
use Authing \Types \OrgParam ;
17
18
use Authing \Types \OrgsParam ;
18
19
use Authing \Types \PaginatedOrgs ;
19
20
use Authing \Types \PaginatedUsers ;
20
21
use Authing \Types \RootNodeParam ;
22
+ use Authing \Types \SetMainDepartmentParam ;
23
+ use Authing \Types \ListNodeByCodeAuthorizedResourcesParam ;
24
+
25
+
21
26
use Exception ;
22
27
use stdClass ;
23
28
@@ -46,7 +51,8 @@ public function __construct($client)
46
51
* @return Org
47
52
* @throws Exception
48
53
*/
49
- public function create ($ name , $ description = null , $ code = null ) {
54
+ public function create ($ name , $ description = null , $ code = null )
55
+ {
50
56
$ param = (new CreateOrgParam ($ name ))->withCode ($ code )->withDescription ($ description );
51
57
return $ this ->client ->request ($ param ->createRequest ());
52
58
}
@@ -58,7 +64,8 @@ public function create($name, $description = null, $code = null) {
58
64
* @return CommonMessage
59
65
* @throws Exception
60
66
*/
61
- public function deleteById ($ id ) {
67
+ public function deleteById ($ id )
68
+ {
62
69
$ param = new DeleteOrgParam ($ id );
63
70
return $ this ->client ->request ($ param ->createRequest ());
64
71
}
@@ -77,13 +84,14 @@ private function buildTree($org)
77
84
* @return PaginatedOrgs
78
85
* @throws Exception
79
86
*/
80
- public function paginate ($ page = 1 , $ limit = 10 ) {
87
+ public function paginate ($ page = 1 , $ limit = 10 )
88
+ {
81
89
$ param = (new OrgsParam ())->withPage ($ page )->withLimit ($ limit );
82
90
// TODO: buildTree
83
91
$ data = $ this ->client ->request ($ param ->createRequest ());
84
92
$ orgs = $ data ->orgs ;
85
93
$ list = $ orgs ->list ;
86
- array_map (function ($ org ) {
94
+ array_map (function ($ org ) {
87
95
$ this ->buildTree ($ org );
88
96
}, $ list );
89
97
$ totalCount = $ orgs ->totalCount ;
@@ -93,11 +101,13 @@ public function paginate($page = 1, $limit = 10) {
93
101
return $ _ ;
94
102
}
95
103
96
- public function addNode ($ orgId , $ parentNodeId , $ data ) {
104
+ public function addNode ($ orgId , $ parentNodeId , $ data )
105
+ {
97
106
98
107
}
99
108
100
- public function updateNode ($ id , $ updates ) {
109
+ public function updateNode ($ id , $ updates )
110
+ {
101
111
102
112
}
103
113
@@ -108,7 +118,8 @@ public function updateNode($id, $updates) {
108
118
* @return Org
109
119
* @throws Exception
110
120
*/
111
- public function findById ($ id ) {
121
+ public function findById ($ id )
122
+ {
112
123
$ param = new OrgParam ($ id );
113
124
// TODO: buildTree
114
125
return $ this ->client ->request ($ param ->createRequest ());
@@ -122,7 +133,8 @@ public function findById($id) {
122
133
* @return CommonMessage
123
134
* @throws Exception
124
135
*/
125
- public function deleteNode ($ orgId , $ nodeId ) {
136
+ public function deleteNode ($ orgId , $ nodeId )
137
+ {
126
138
$ param = new DeleteNodeParam ($ orgId , $ nodeId );
127
139
return $ this ->client ->request ($ param ->createRequest ());
128
140
}
@@ -136,7 +148,8 @@ public function deleteNode($orgId, $nodeId) {
136
148
* @return Org
137
149
* @throws Exception
138
150
*/
139
- public function moveNode ($ orgId , $ nodeId , $ targetParentId ) {
151
+ public function moveNode ($ orgId , $ nodeId , $ targetParentId )
152
+ {
140
153
$ param = new MoveNodeParam ($ orgId , $ nodeId , $ targetParentId );
141
154
// TODO: buildTree
142
155
return $ this ->client ->request ($ param ->createRequest ());
@@ -150,7 +163,8 @@ public function moveNode($orgId, $nodeId, $targetParentId) {
150
163
* @return boolean
151
164
* @throws Exception
152
165
*/
153
- public function isRootNode ($ orgId , $ nodeId ) {
166
+ public function isRootNode ($ orgId , $ nodeId )
167
+ {
154
168
$ param = new IsRootNodeParam ($ orgId , $ nodeId );
155
169
return $ this ->client ->request ($ param ->createRequest ());
156
170
}
@@ -163,7 +177,8 @@ public function isRootNode($orgId, $nodeId) {
163
177
* @return Node[]
164
178
* @throws Exception
165
179
*/
166
- public function listChildren ($ orgId , $ nodeId ) {
180
+ public function listChildren ($ orgId , $ nodeId )
181
+ {
167
182
$ param = new ChildrenNodesParam ($ orgId , $ nodeId );
168
183
return $ this ->client ->request ($ param ->createRequest ());
169
184
}
@@ -175,16 +190,19 @@ public function listChildren($orgId, $nodeId) {
175
190
* @return Node[]
176
191
* @throws Exception
177
192
*/
178
- public function rootNode ($ orgId ) {
193
+ public function rootNode ($ orgId )
194
+ {
179
195
$ param = new RootNodeParam ($ orgId );
180
196
return $ this ->client ->request ($ param ->createRequest ());
181
197
}
182
198
183
- public function importByJson ($ json ) {
199
+ public function importByJson ($ json )
200
+ {
184
201
185
202
}
186
203
187
- public function addMembers ($ nodeId , $ userIds ) {
204
+ public function addMembers ($ nodeId , $ userIds )
205
+ {
188
206
189
207
}
190
208
@@ -195,11 +213,75 @@ public function addMembers($nodeId, $userIds) {
195
213
* @return PaginatedUsers
196
214
* @throws Exception
197
215
*/
198
- public function listMembers ($ param ) {
216
+ public function listMembers ($ param )
217
+ {
199
218
return $ this ->client ->request ($ param ->createRequest ())->users ;
200
219
}
201
220
202
- public function removeMembers ($ nodeId , $ userIds ) {
221
+ public function removeMembers ($ nodeId , $ userIds )
222
+ {
223
+
224
+ }
225
+
226
+ public function getNodeById (string $ nodeId )
227
+ {
228
+ $ param = new NodeByIdParam ($ nodeId );
229
+ $ node = $ this ->client ->request ($ param ->createRequest ())->nodeById ;
230
+ return $ node ;
231
+ }
232
+
233
+ public function exportAll ()
234
+ {
235
+ $ data = $ this ->client ->httpGet ('/api/v2/orgs/export ' );
236
+ return $ data ;
237
+ }
238
+
239
+ public function setMainDepartment (string $ userId , string $ departmentId )
240
+ {
241
+ $ param = (new SetMainDepartmentParam ($ userId ))->withDepartmentId ($ departmentId );
242
+ $ data = $ this ->client ->request ($ param ->createRequest ())->setMainDepartment ;
243
+ return $ data ;
244
+ }
245
+
246
+ public function exportByOrgId (string $ orgId )
247
+ {
248
+ $ data = $ this ->client ->httpGet ("/api/v2/orgs/export?org_id= $ orgId " );
249
+ return $ data ;
250
+ }
251
+
252
+ public function listAuthorizedResourcesByNodeId (string $ nodeId , string $ namespace , array $ options = [])
253
+ {
254
+ $ resourceType = $ options ['resourceType ' ] ?? new stdClass ;
255
+ $ param = (new ListNodeByIdAuthorizedResourcesParam ($ nodeId ))->withNamespace ($ namespace )->withResourceType ($ resourceType );
256
+ $ node = $ this ->client ->request ($ param ->createRequest ())->nodeById ;
257
+ if (!$ node ) {
258
+ throw new Error ('组织机构节点不存在 ' );
259
+ }
260
+ $ list = $ node ->authorizedResources ->list ;
261
+ $ totalCount = $ node ->authorizedResources ->totalCount ;
203
262
263
+ $ list = formatAuthorizedResources ($ list );
264
+ $ _ = new stdClass ;
265
+ $ _ ->list = $ list ;
266
+ $ _ ->totalCount = $ totalCount ;
267
+ return $ _ ;
268
+ }
269
+
270
+ public function listAuthorizedResourcesByNodeCode (string $ orgId , string $ code , string $ namespace , array $ options = [])
271
+ {
272
+ $ resourceType = $ options ['resourceType ' ] ?? new stdClass ;
273
+ $ param = (new ListNodeByCodeAuthorizedResourcesParam ($ orgId , $ code ))->withNamespace ($ namespace )->withResourceType ($ resourceType );
274
+ $ node = $ this ->client ->request ($ param ->createRequest ())->nodeById ;
275
+ if (!$ node ) {
276
+ throw new Error ('组织机构节点不存在 ' );
277
+ }
278
+ $ list = $ node ->authorizedResources ->list ;
279
+ $ totalCount = $ node ->authorizedResources ->totalCount ;
280
+
281
+ $ list = formatAuthorizedResources ($ list );
282
+ $ _ = new stdClass ;
283
+ $ _ ->list = $ list ;
284
+ $ _ ->totalCount = $ totalCount ;
285
+ return $ _ ;
204
286
}
205
- }
287
+ }
0 commit comments