From 43d2be6e99696dfc429584ae206c0494a40a69bc Mon Sep 17 00:00:00 2001 From: NAmorim Date: Thu, 25 Nov 2021 23:44:14 +0000 Subject: [PATCH 1/2] Better handling of user fork --- Platform/Client/githubServer.js | 5 +- .../Function-Libraries/ProfileConstructor.js | 57 ------------------- 2 files changed, 1 insertion(+), 61 deletions(-) diff --git a/Platform/Client/githubServer.js b/Platform/Client/githubServer.js index b3b08503e..9deeef126 100644 --- a/Platform/Client/githubServer.js +++ b/Platform/Client/githubServer.js @@ -163,17 +163,14 @@ exports.newGithubServer = function newGithubServer() { } } - async function createGithubFork(repository, username, token) { + async function createGithubFork(token) { try { - username = unescape(username) token = unescape(token) await doGithub() async function doGithub() { try { - //const repo = 'Superalgos' - //const owner = username const { Octokit } = SA.nodeModules.octokit const octokit = new Octokit({ auth: token, diff --git a/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js b/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js index 940b853b2..bc92d6b46 100644 --- a/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js +++ b/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js @@ -145,63 +145,6 @@ function newGovernanceFunctionLibraryProfileConstructor() { liquidProg.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 liquidProg.payload.uiObject.menu.internalClick('Add Tokens Awarded') /* - Check if the user already has the SA fork. If not, do it for them. - */ - - /* - const hasFork = UI.projects.governance.spaces.userProfileSpace.githubForks.get(githubUsername) - if (hasFork === undefined) { - // New user! Probably doesn't have a fork, so let's create it. - let apisNode = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadByNodeType('APIs') - if (apisNode === undefined) { - UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Error - Github Credentials Missing', 'Anchor Github Credentials Missing') - return - } - if (apisNode.githubAPI === undefined) { - UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Error - Github Credentials Missing', 'Anchor Github Credentials Missing') - return - } - - let config = JSON.parse(apisNode.githubAPI.config) - if (config.username === undefined || config.username === "") { - UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Error - Github Credentials Missing', 'Anchor Github Credentials Missing') - return - } - if (config.token === undefined || config.token === "") { - UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Error - Github Credentials Missing', 'Anchor Github Credentials Missing') - return - } - - let params = { - method: 'createGithubFork', - username: config.username, - token: config.token, - } - - let url = 'GOV' // We will access the default Client GOV endpoint. - - httpRequest(JSON.stringify(params), url, onResponse) - - function onResponse(err, data) { - - data = JSON.parse(data) - if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result && data.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { - UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Message - Automated User Profile Contribute Done') - } else { - if (data.docs === undefined) { return } - UI.projects.education.spaces.docsSpace.navigateTo( - data.docs.project, - data.docs.category, - data.docs.type, - data.docs.anchor, - undefined, - data.docs.placeholder - ) - } - } - } - */ - /* We store at the User Profile the Signed githubUsername */ UI.projects.visualScripting.utilities.nodeConfig.saveConfigProperty(userProfile.payload, 'signature', response.signature) From f318bcdf1585ac3cd6e0da63fb87d7f106da6b32 Mon Sep 17 00:00:00 2001 From: NAmorim Date: Fri, 26 Nov 2021 01:09:32 +0000 Subject: [PATCH 2/2] Better handling of user fork --- Platform/Client/githubServer.js | 5 +- Platform/Client/httpInterface.js | 15 ++++- .../Function-Libraries/ProfileConstructor.js | 57 ------------------- 3 files changed, 14 insertions(+), 63 deletions(-) diff --git a/Platform/Client/githubServer.js b/Platform/Client/githubServer.js index b3b08503e..9deeef126 100644 --- a/Platform/Client/githubServer.js +++ b/Platform/Client/githubServer.js @@ -163,17 +163,14 @@ exports.newGithubServer = function newGithubServer() { } } - async function createGithubFork(repository, username, token) { + async function createGithubFork(token) { try { - username = unescape(username) token = unescape(token) await doGithub() async function doGithub() { try { - //const repo = 'Superalgos' - //const owner = username const { Octokit } = SA.nodeModules.octokit const octokit = new Octokit({ auth: token, diff --git a/Platform/Client/httpInterface.js b/Platform/Client/httpInterface.js index e355b31ca..8f9724480 100644 --- a/Platform/Client/httpInterface.js +++ b/Platform/Client/httpInterface.js @@ -1315,8 +1315,6 @@ exports.newHttpInterface = function newHttpInterface() { case 'createGithubFork': { let serverResponse = await PL.servers.GITHUB_SERVER.createGithubFork( - params.repository, - params.username, params.token ) @@ -1355,8 +1353,21 @@ exports.newHttpInterface = function newHttpInterface() { let error + await checkFork() await updateUser() + async function checkFork() { + let serverResponse = await PL.servers.GITHUB_SERVER.createGithubFork( + params.token + ) + + SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(serverResponse), httpResponse) + + if(error != undefined) { + console.log('[ERROR] httpInterface -> Gov -> createFork -> You already have a fork. Good for you!') + } + } + async function updateUser() { await doGithubUser() diff --git a/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js b/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js index 940b853b2..bc92d6b46 100644 --- a/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js +++ b/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js @@ -145,63 +145,6 @@ function newGovernanceFunctionLibraryProfileConstructor() { liquidProg.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 liquidProg.payload.uiObject.menu.internalClick('Add Tokens Awarded') /* - Check if the user already has the SA fork. If not, do it for them. - */ - - /* - const hasFork = UI.projects.governance.spaces.userProfileSpace.githubForks.get(githubUsername) - if (hasFork === undefined) { - // New user! Probably doesn't have a fork, so let's create it. - let apisNode = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadByNodeType('APIs') - if (apisNode === undefined) { - UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Error - Github Credentials Missing', 'Anchor Github Credentials Missing') - return - } - if (apisNode.githubAPI === undefined) { - UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Error - Github Credentials Missing', 'Anchor Github Credentials Missing') - return - } - - let config = JSON.parse(apisNode.githubAPI.config) - if (config.username === undefined || config.username === "") { - UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Error - Github Credentials Missing', 'Anchor Github Credentials Missing') - return - } - if (config.token === undefined || config.token === "") { - UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Error - Github Credentials Missing', 'Anchor Github Credentials Missing') - return - } - - let params = { - method: 'createGithubFork', - username: config.username, - token: config.token, - } - - let url = 'GOV' // We will access the default Client GOV endpoint. - - httpRequest(JSON.stringify(params), url, onResponse) - - function onResponse(err, data) { - - data = JSON.parse(data) - if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result && data.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { - UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Message - Automated User Profile Contribute Done') - } else { - if (data.docs === undefined) { return } - UI.projects.education.spaces.docsSpace.navigateTo( - data.docs.project, - data.docs.category, - data.docs.type, - data.docs.anchor, - undefined, - data.docs.placeholder - ) - } - } - } - */ - /* We store at the User Profile the Signed githubUsername */ UI.projects.visualScripting.utilities.nodeConfig.saveConfigProperty(userProfile.payload, 'signature', response.signature)