From 3c6b88ce4e4f9a3672b9fb19b7179933c381303e Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Thu, 30 May 2024 11:23:27 -0500 Subject: [PATCH] CLDR-16499 CLA: refactor client code out per code review --- tools/cldr-apps/js/src/esm/cldrCla.mjs | 58 +++++++++++++++++++++++ tools/cldr-apps/js/src/views/MainMenu.vue | 3 +- tools/cldr-apps/js/src/views/SignCla.vue | 55 +++++++-------------- 3 files changed, 78 insertions(+), 38 deletions(-) create mode 100644 tools/cldr-apps/js/src/esm/cldrCla.mjs diff --git a/tools/cldr-apps/js/src/esm/cldrCla.mjs b/tools/cldr-apps/js/src/esm/cldrCla.mjs new file mode 100644 index 00000000000..90ce7eac47a --- /dev/null +++ b/tools/cldr-apps/js/src/esm/cldrCla.mjs @@ -0,0 +1,58 @@ +import * as cldrClient from "../esm/cldrClient.mjs"; +import * as cldrNotify from "../esm/cldrNotify.mjs"; +/** + * see ClaSignature.java + * @typedef {Object} ClaSignature + * @property {boolean} corporate true if a corporate signature + * @property {string} email + * @property {string} employer + * @property {string} name + * @property {boolean} unauthorized true if cla load failed + * @property {boolean} readonly true if cla may not be modified + * @property {boolean} signed true if signed, always true when returned from getCla() + */ + +/** @return {ClaSignature} signed cla if present otherwise null if not accessible */ +export async function getCla() { + try { + const client = await cldrClient.getClient(); + const { body } = await client.apis.user.getCla(); + return body; + } catch (e) { + if (e.statusCode === 401) { + return { unauthorized: true }; + } else if (e.statusCode === 404) { + return { signed: false }; + } else { + cldrNotify.exception(e, `trying to load CLA`); + throw e; + } + } +} + +/** + * Attempt to sign. + * @throws {statusCode: 423} if the CLA may not be modified + * @throws {statusCode: 406} if there is an imput validation error + * @param {ClaSignature} cla + * @returns nothing if successful + */ +export async function signCla(cla) { + const client = await cldrClient.getClient(); + const result = await client.apis.user.signCla( + {}, + { + requestBody: cla, + } + ); +} + +/** + * Attempt to revoke. + * @throws {statusCode: 423} if the CLA may not be modified + * @throws {statusCode: 404} if the CLA was never signed + */ +export async function revokeCla() { + const client = await cldrClient.getClient(); + const result = await client.apis.user.revokeCla(); +} diff --git a/tools/cldr-apps/js/src/views/MainMenu.vue b/tools/cldr-apps/js/src/views/MainMenu.vue index 28b563c13a6..0872397d68d 100644 --- a/tools/cldr-apps/js/src/views/MainMenu.vue +++ b/tools/cldr-apps/js/src/views/MainMenu.vue @@ -8,7 +8,7 @@
  • @@ -139,6 +139,7 @@ export default { recentActivityUrl: null, uploadXmlUrl: null, userId: 0, + showClaMenu: false, // off by default, see CLDR-16499 }; }, diff --git a/tools/cldr-apps/js/src/views/SignCla.vue b/tools/cldr-apps/js/src/views/SignCla.vue index 0202592229c..3f3def5191c 100644 --- a/tools/cldr-apps/js/src/views/SignCla.vue +++ b/tools/cldr-apps/js/src/views/SignCla.vue @@ -93,12 +93,12 @@