Support to retrieve the username of an account via REST
By GET on /accounts/<account-id>/username it is now possible to retrieve the username of an account. Change-Id: I061dbc2f59920edb7421c6341854a42b36c782ca Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:

committed by
Edwin Kempin

parent
20092b132e
commit
9f9ec65cf4
@@ -161,6 +161,31 @@ Deletes the name of an account.
|
|||||||
HTTP/1.1 204 No Content
|
HTTP/1.1 204 No Content
|
||||||
----
|
----
|
||||||
|
|
||||||
|
[[get-username]]
|
||||||
|
Get Username
|
||||||
|
~~~~~~~~~~~~
|
||||||
|
[verse]
|
||||||
|
'GET /accounts/link:#account-id[\{account-id\}]/username'
|
||||||
|
|
||||||
|
Retrieves the username of an account.
|
||||||
|
|
||||||
|
.Request
|
||||||
|
----
|
||||||
|
GET /accounts/self/username HTTP/1.0
|
||||||
|
----
|
||||||
|
|
||||||
|
.Response
|
||||||
|
----
|
||||||
|
HTTP/1.1 200 OK
|
||||||
|
Content-Disposition: attachment
|
||||||
|
Content-Type: application/json;charset=UTF-8
|
||||||
|
|
||||||
|
)]}'
|
||||||
|
"john.doe"
|
||||||
|
----
|
||||||
|
|
||||||
|
If the account does not have a username the response is `404 Not Found`.
|
||||||
|
|
||||||
[[get-active]]
|
[[get-active]]
|
||||||
Get Active
|
Get Active
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
|
@@ -0,0 +1,46 @@
|
|||||||
|
// Copyright (C) 2013 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.server.account;
|
||||||
|
|
||||||
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
|
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||||
|
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||||
|
import com.google.gerrit.server.CurrentUser;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
|
public class GetUsername implements RestReadView<AccountResource> {
|
||||||
|
|
||||||
|
private final Provider<CurrentUser> self;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
GetUsername(Provider<CurrentUser> self) {
|
||||||
|
this.self = self;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apply(AccountResource rsrc) throws AuthException,
|
||||||
|
ResourceNotFoundException {
|
||||||
|
if (self.get() != rsrc.getUser()
|
||||||
|
&& !self.get().getCapabilities().canAdministrateServer()) {
|
||||||
|
throw new AuthException("not allowed to get username");
|
||||||
|
}
|
||||||
|
String username = rsrc.getUser().getAccount().getUserName();
|
||||||
|
if (username == null) {
|
||||||
|
throw new ResourceNotFoundException();
|
||||||
|
}
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
}
|
@@ -39,6 +39,7 @@ public class Module extends RestApiModule {
|
|||||||
get(ACCOUNT_KIND, "name").to(GetName.class);
|
get(ACCOUNT_KIND, "name").to(GetName.class);
|
||||||
put(ACCOUNT_KIND, "name").to(PutName.class);
|
put(ACCOUNT_KIND, "name").to(PutName.class);
|
||||||
delete(ACCOUNT_KIND, "name").to(PutName.class);
|
delete(ACCOUNT_KIND, "name").to(PutName.class);
|
||||||
|
get(ACCOUNT_KIND, "username").to(GetUsername.class);
|
||||||
get(ACCOUNT_KIND, "active").to(GetActive.class);
|
get(ACCOUNT_KIND, "active").to(GetActive.class);
|
||||||
put(ACCOUNT_KIND, "active").to(PutActive.class);
|
put(ACCOUNT_KIND, "active").to(PutActive.class);
|
||||||
delete(ACCOUNT_KIND, "active").to(DeleteActive.class);
|
delete(ACCOUNT_KIND, "active").to(DeleteActive.class);
|
||||||
|
Reference in New Issue
Block a user