diff options
Diffstat (limited to 'server/sonar-web/src/main/js/api/user-tokens.js')
-rw-r--r-- | server/sonar-web/src/main/js/api/user-tokens.js | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/server/sonar-web/src/main/js/api/user-tokens.js b/server/sonar-web/src/main/js/api/user-tokens.js index 4b3b97e2bba..3947b07f1be 100644 --- a/server/sonar-web/src/main/js/api/user-tokens.js +++ b/server/sonar-web/src/main/js/api/user-tokens.js @@ -17,14 +17,16 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +// @flow import { getJSON, postJSON, post } from '../helpers/request'; +import throwGlobalError from '../app/utils/throwGlobalError'; /** * List tokens for given user login * @param {string} login * @returns {Promise} */ -export function getTokens(login) { +export function getTokens(login: string) { const url = '/api/user_tokens/search'; const data = { login }; return getJSON(url, data).then(r => r.userTokens); @@ -36,10 +38,16 @@ export function getTokens(login) { * @param {string} tokenName * @returns {Promise} */ -export function generateToken(userLogin, tokenName) { +export function generateToken( + tokenName: string, + userLogin?: string +): Promise<{ name: string, token: string }> { const url = '/api/user_tokens/generate'; - const data = { login: userLogin, name: tokenName }; - return postJSON(url, data); + const data: { [string]: string } = { name: tokenName }; + if (userLogin) { + data.login = userLogin; + } + return postJSON(url, data).catch(throwGlobalError); } /** @@ -48,8 +56,11 @@ export function generateToken(userLogin, tokenName) { * @param {string} tokenName * @returns {Promise} */ -export function revokeToken(userLogin, tokenName) { +export function revokeToken(tokenName: string, userLogin?: string) { const url = '/api/user_tokens/revoke'; - const data = { login: userLogin, name: tokenName }; - return post(url, data); + const data: { [string]: string } = { name: tokenName }; + if (userLogin) { + data.login = userLogin; + } + return post(url, data).catch(throwGlobalError); } |