Skip to content

Commit 09172a1

Browse files
committed
Add pagers to server clients and client authorizations in OAuth Server GUI
Summary: ...also make the pager usage in ChatLog use the nice formatWhereClause functionality Test Plan: set $page_size = 2 and paged around the data a bit Reviewers: epriestley Reviewed By: epriestley CC: aran Maniphest Tasks: T905 Differential Revision: https://secure.phabricator.com/D2106
1 parent 05b4c90 commit 09172a1

File tree

10 files changed

+192
-23
lines changed

10 files changed

+192
-23
lines changed

src/__phutil_library_map__.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@
677677
'PhabricatorOAuthClientAuthorizationDeleteController' => 'applications/oauthserver/controller/clientauthorization/delete',
678678
'PhabricatorOAuthClientAuthorizationEditController' => 'applications/oauthserver/controller/clientauthorization/edit',
679679
'PhabricatorOAuthClientAuthorizationListController' => 'applications/oauthserver/controller/clientauthorization/list',
680+
'PhabricatorOAuthClientAuthorizationQuery' => 'applications/oauthserver/query/clientauthorization',
680681
'PhabricatorOAuthClientBaseController' => 'applications/oauthserver/controller/client/base',
681682
'PhabricatorOAuthClientDeleteController' => 'applications/oauthserver/controller/client/delete',
682683
'PhabricatorOAuthClientEditController' => 'applications/oauthserver/controller/client/edit',
@@ -698,6 +699,7 @@
698699
'PhabricatorOAuthServerAuthController' => 'applications/oauthserver/controller/auth',
699700
'PhabricatorOAuthServerAuthorizationCode' => 'applications/oauthserver/storage/authorizationcode',
700701
'PhabricatorOAuthServerClient' => 'applications/oauthserver/storage/client',
702+
'PhabricatorOAuthServerClientQuery' => 'applications/oauthserver/query/client',
701703
'PhabricatorOAuthServerController' => 'applications/oauthserver/controller/base',
702704
'PhabricatorOAuthServerDAO' => 'applications/oauthserver/storage/base',
703705
'PhabricatorOAuthServerScope' => 'applications/oauthserver/scope',
@@ -1510,6 +1512,7 @@
15101512
'PhabricatorOAuthClientAuthorizationDeleteController' => 'PhabricatorOAuthClientAuthorizationBaseController',
15111513
'PhabricatorOAuthClientAuthorizationEditController' => 'PhabricatorOAuthClientAuthorizationBaseController',
15121514
'PhabricatorOAuthClientAuthorizationListController' => 'PhabricatorOAuthClientAuthorizationBaseController',
1515+
'PhabricatorOAuthClientAuthorizationQuery' => 'PhabricatorOffsetPagedQuery',
15131516
'PhabricatorOAuthClientBaseController' => 'PhabricatorOAuthServerController',
15141517
'PhabricatorOAuthClientDeleteController' => 'PhabricatorOAuthClientBaseController',
15151518
'PhabricatorOAuthClientEditController' => 'PhabricatorOAuthClientBaseController',
@@ -1529,6 +1532,7 @@
15291532
'PhabricatorOAuthServerAuthController' => 'PhabricatorAuthController',
15301533
'PhabricatorOAuthServerAuthorizationCode' => 'PhabricatorOAuthServerDAO',
15311534
'PhabricatorOAuthServerClient' => 'PhabricatorOAuthServerDAO',
1535+
'PhabricatorOAuthServerClientQuery' => 'PhabricatorOffsetPagedQuery',
15321536
'PhabricatorOAuthServerController' => 'PhabricatorController',
15331537
'PhabricatorOAuthServerDAO' => 'PhabricatorLiskDAO',
15341538
'PhabricatorOAuthServerTestCase' => 'PhabricatorTestCase',

src/applications/chatlog/query/PhabricatorChatLogQuery.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ private function buildWhereClause($conn_r) {
5353
$this->channels);
5454
}
5555

56-
if ($where) {
57-
$where = 'WHERE ('.implode(') AND (', $where).')';
58-
} else {
59-
$where = '';
60-
}
61-
62-
return $where;
56+
return $this->formatWhereClause($where);
6357
}
6458
}

src/applications/oauthserver/controller/client/list/PhabricatorOAuthClientListController.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,17 @@ public function processRequest() {
3030
$title = 'OAuth Clients';
3131
$request = $this->getRequest();
3232
$current_user = $request->getUser();
33-
$clients = id(new PhabricatorOAuthServerClient())
34-
->loadAllWhere('creatorPHID = %s',
35-
$current_user->getPHID());
33+
$offset = $request->getInt('offset', 0);
34+
$page_size = 100;
35+
$pager = new AphrontPagerView();
36+
$request_uri = $request->getRequestURI();
37+
$pager->setURI($request_uri, 'offset');
38+
$pager->setPageSize($page_size);
39+
$pager->setOffset($offset);
40+
41+
$query = new PhabricatorOAuthServerClientQuery();
42+
$query->withCreatorPHIDs(array($current_user->getPHID()));
43+
$clients = $query->executeWithPager($pager);
3644

3745
$rows = array();
3846
$rowc = array();
@@ -76,8 +84,10 @@ public function processRequest() {
7684
$panel = $this->buildClientList($rows, $rowc, $title);
7785

7886
return $this->buildStandardPageResponse(
79-
array($this->getNoticeView(),
80-
$panel),
87+
array(
88+
$this->getNoticeView(),
89+
$panel->appendChild($pager)
90+
),
8191
array('title' => $title)
8292
);
8393
}

src/applications/oauthserver/controller/client/list/__init__.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88

99
phutil_require_module('phabricator', 'applications/oauthserver/controller/client/base');
10-
phutil_require_module('phabricator', 'applications/oauthserver/storage/client');
10+
phutil_require_module('phabricator', 'applications/oauthserver/query/client');
11+
phutil_require_module('phabricator', 'view/control/pager');
1112
phutil_require_module('phabricator', 'view/control/table');
1213
phutil_require_module('phabricator', 'view/form/error');
1314
phutil_require_module('phabricator', 'view/layout/panel');
1415

1516
phutil_require_module('phutil', 'markup');
16-
phutil_require_module('phutil', 'utils');
1717

1818

1919
phutil_require_source('PhabricatorOAuthClientListController.php');

src/applications/oauthserver/controller/clientauthorization/list/PhabricatorOAuthClientAuthorizationListController.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,20 @@ protected function getFilter() {
2727
}
2828

2929
public function processRequest() {
30-
$title = 'OAuth Client Authorizations';
31-
$request = $this->getRequest();
32-
$current_user = $request->getUser();
33-
$authorizations = id(new PhabricatorOAuthClientAuthorization())
34-
->loadAllWhere('userPHID = %s',
35-
$current_user->getPHID());
30+
$title = 'OAuth Client Authorizations';
31+
$request = $this->getRequest();
32+
$current_user = $request->getUser();
33+
$offset = $request->getInt('offset', 0);
34+
$page_size = 100;
35+
$pager = new AphrontPagerView();
36+
$request_uri = $request->getRequestURI();
37+
$pager->setURI($request_uri, 'offset');
38+
$pager->setPageSize($page_size);
39+
$pager->setOffset($offset);
40+
41+
$query = new PhabricatorOAuthClientAuthorizationQuery();
42+
$query->withUserPHIDs(array($current_user->getPHID()));
43+
$authorizations = $query->executeWithPager($pager);
3644

3745
$client_authorizations = mpull($authorizations, null, 'getClientPHID');
3846
$client_phids = array_keys($client_authorizations);
@@ -101,8 +109,10 @@ public function processRequest() {
101109
$panel = $this->buildClientAuthorizationList($rows, $rowc, $title);
102110

103111
return $this->buildStandardPageResponse(
104-
array($this->getNoticeView(),
105-
$panel),
112+
array(
113+
$this->getNoticeView(),
114+
$panel->appendChild($pager),
115+
),
106116
array('title' => $title)
107117
);
108118
}

src/applications/oauthserver/controller/clientauthorization/list/__init__.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88

99
phutil_require_module('phabricator', 'applications/oauthserver/controller/clientauthorization/base');
10+
phutil_require_module('phabricator', 'applications/oauthserver/query/clientauthorization');
1011
phutil_require_module('phabricator', 'applications/oauthserver/storage/client');
11-
phutil_require_module('phabricator', 'applications/oauthserver/storage/clientauthorization');
1212
phutil_require_module('phabricator', 'infrastructure/env');
13+
phutil_require_module('phabricator', 'view/control/pager');
1314
phutil_require_module('phabricator', 'view/control/table');
1415
phutil_require_module('phabricator', 'view/form/error');
1516
phutil_require_module('phabricator', 'view/layout/panel');
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2012 Facebook, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
final class PhabricatorOAuthServerClientQuery
20+
extends PhabricatorOffsetPagedQuery {
21+
private $creatorPHIDs;
22+
23+
public function withCreatorPHIDs(array $phids) {
24+
$this->creatorPHIDs = $phids;
25+
return $this;
26+
}
27+
private function getCreatorPHIDs() {
28+
return $this->creatorPHIDs;
29+
}
30+
31+
public function execute() {
32+
$table = new PhabricatorOAuthServerClient();
33+
$conn_r = $table->establishConnection('r');
34+
35+
$where_clause = $this->buildWhereClause($conn_r);
36+
$limit_clause = $this->buildLimitClause($conn_r);
37+
38+
$data = queryfx_all(
39+
$conn_r,
40+
'SELECT * FROM %T client %Q %Q',
41+
$table->getTableName(),
42+
$where_clause,
43+
$limit_clause);
44+
45+
return $table->loadAllFromArray($data);
46+
}
47+
48+
private function buildWhereClause($conn_r) {
49+
$where = array();
50+
51+
if ($this->getCreatorPHIDs()) {
52+
$where[] = qsprintf(
53+
$conn_r,
54+
'creatorPHID IN (%Ls)',
55+
$this->getCreatorPHIDs());
56+
}
57+
58+
return $this->formatWhereClause($where);
59+
}
60+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* This file is automatically generated. Lint this module to rebuild it.
4+
* @generated
5+
*/
6+
7+
8+
9+
phutil_require_module('phabricator', 'applications/oauthserver/storage/client');
10+
phutil_require_module('phabricator', 'infrastructure/query/offsetpaged');
11+
phutil_require_module('phabricator', 'storage/qsprintf');
12+
phutil_require_module('phabricator', 'storage/queryfx');
13+
14+
15+
phutil_require_source('PhabricatorOAuthServerClientQuery.php');
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2012 Facebook, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
final class PhabricatorOAuthClientAuthorizationQuery
20+
extends PhabricatorOffsetPagedQuery {
21+
private $userPHIDs;
22+
23+
public function withUserPHIDs(array $phids) {
24+
$this->userPHIDs = $phids;
25+
return $this;
26+
}
27+
private function getUserPHIDs() {
28+
return $this->userPHIDs;
29+
}
30+
31+
public function execute() {
32+
$table = new PhabricatorOAuthClientAuthorization();
33+
$conn_r = $table->establishConnection('r');
34+
35+
$where_clause = $this->buildWhereClause($conn_r);
36+
$limit_clause = $this->buildLimitClause($conn_r);
37+
38+
$data = queryfx_all(
39+
$conn_r,
40+
'SELECT * FROM %T auth %Q %Q',
41+
$table->getTableName(),
42+
$where_clause,
43+
$limit_clause);
44+
45+
return $table->loadAllFromArray($data);
46+
}
47+
48+
private function buildWhereClause($conn_r) {
49+
$where = array();
50+
51+
if ($this->getUserPHIDs()) {
52+
$where[] = qsprintf(
53+
$conn_r,
54+
'userPHID IN (%Ls)',
55+
$this->getUserPHIDs());
56+
}
57+
58+
return $this->formatWhereClause($where);
59+
}
60+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* This file is automatically generated. Lint this module to rebuild it.
4+
* @generated
5+
*/
6+
7+
8+
9+
phutil_require_module('phabricator', 'applications/oauthserver/storage/clientauthorization');
10+
phutil_require_module('phabricator', 'infrastructure/query/offsetpaged');
11+
phutil_require_module('phabricator', 'storage/qsprintf');
12+
phutil_require_module('phabricator', 'storage/queryfx');
13+
14+
15+
phutil_require_source('PhabricatorOAuthClientAuthorizationQuery.php');

0 commit comments

Comments
 (0)