Added method cvat.server.authorized() (#641)

* Added method cvat.server.authorized()
* Typos
main
Boris Sekachev 7 years ago committed by Nikita Manovich
parent 3a6a49625c
commit f797d3ac53

@ -58,6 +58,11 @@
await serverProxy.server.logout();
};
cvat.server.authorized.implementation = async () => {
const result = await serverProxy.server.authorized();
return result;
};
cvat.users.get.implementation = async (filter) => {
checkFilter(filter, {
self: isBoolean,

@ -144,6 +144,20 @@ function build() {
.apiWrapper(cvat.server.logout);
return result;
},
/**
* Method allows to know whether you are authorized on the server
* @method authorized
* @async
* @memberof module:API.cvat.server
* @returns {boolean}
* @throws {module:API.cvat.exceptions.PluginError}
* @throws {module:API.cvat.exceptions.ServerError}
*/
async authorized() {
const result = await PluginRegistry
.apiWrapper(cvat.server.authorized);
return result;
},
},
/**
* Namespace is used for getting tasks

@ -222,6 +222,20 @@
}
}
async function authorized() {
try {
await module.exports.users.getSelf();
} catch (serverError) {
if (serverError.code === 403) {
return false;
}
throw serverError;
}
return true;
}
async function getTasks(filter = '') {
const { backendAPI } = config;
@ -441,7 +455,7 @@
} catch (errorData) {
const code = errorData.response ? errorData.response.status : errorData.code;
throw new ServerError(
'Could not get users from the server',
'Could not get user data from the server',
code,
);
}
@ -626,6 +640,7 @@
exception,
login,
logout,
authorized,
}),
writable: false,
},

Loading…
Cancel
Save