From 513738a22ddcfb12c84c9b3dee6c1ab790678eed Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 8 Aug 2021 14:50:33 +0200 Subject: [PATCH] Governance: Simplification of the Process to create a Profile --- Client/githubServer.js | 25 +++++++++++- .../App-Schema/governance-project.json | 7 ---- .../Function-Libraries/ProfileConstructor.js | 38 +++++++++++++------ 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/Client/githubServer.js b/Client/githubServer.js index ea1f2f991..8bcfe0fab 100644 --- a/Client/githubServer.js +++ b/Client/githubServer.js @@ -224,7 +224,7 @@ exports.newGithubServer = function newGithubServer() { page++ await CL.projects.foundations.utilities.asyncFunctions.sleep(GITHUB_API_WAITING_TIME) - + let listResponse = await octokit.rest.pulls.list({ owner: owner, repo: repo, @@ -400,6 +400,29 @@ exports.newGithubServer = function newGithubServer() { continue } /* + Validation #5: The name of the User Profile node is not the Github Username. + */ + if (userProfile.name !== githubUsername) { + console.log('[INFO] Github Server -> mergeGithubPullRequests -> Validation #5 Failed -> Pull Request "' + pullRequest.title + '" not merged because the Github Username is not equal to the User Profile node\'s name. -> Github Username = ' + githubUsername + '-> userProfile.name = ' + userProfile.name) + + await CL.projects.foundations.utilities.asyncFunctions.sleep(GITHUB_API_WAITING_TIME) + await octokit.rest.issues.createComment({ + owner: owner, + repo: repo, + issue_number: pullRequest.number, + body: 'This Pull Request could not be automatically merged and was closed by the Superalgos Governance System because it was detected that the Github User "' + githubUsername + '" who submitted it, is not equal to the User Profile node\'s name.\n\n User Profile Name = "' + userProfile.name + '"' + }); + + await CL.projects.foundations.utilities.asyncFunctions.sleep(GITHUB_API_WAITING_TIME) + await octokit.rest.pulls.update({ + owner: owner, + repo: repo, + pull_number: pullRequest.number, + state: 'closed' + }); + continue + } + /* All validations passed, we will proceed an merge this Pull Request. */ await CL.projects.foundations.utilities.asyncFunctions.sleep(GITHUB_API_WAITING_TIME) diff --git a/Projects/Governance/Schemas/App-Schema/governance-project.json b/Projects/Governance/Schemas/App-Schema/governance-project.json index 4849e91c3..03e9198ec 100644 --- a/Projects/Governance/Schemas/App-Schema/governance-project.json +++ b/Projects/Governance/Schemas/App-Schema/governance-project.json @@ -29,13 +29,6 @@ "relatedUiObject": "Positions", "actionFunction": "payload.executeAction" }, - { - "action": "Add UI Object", - "actionProject": "Foundations", - "label": "Add User Profile", - "relatedUiObject": "User Profile", - "actionFunction": "payload.executeAction" - }, { "action": "Add UI Object", "actionProject": "Foundations", diff --git a/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js b/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js index 7f07298e3..5ec64f420 100644 --- a/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js +++ b/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js @@ -12,17 +12,19 @@ function newGovernanceFunctionLibraryProfileConstructor() { /* Some validations first... */ - if (node.payload.referenceParent === undefined) { - node.payload.uiObject.setErrorMessage("You need to reference the node that contains the data to be signed.") - return - } - let data = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'githubUsername') + let githubUsername = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'githubUsername') - if (data === undefined || data === "") { - node.payload.referenceParent.payload.uiObject.setErrorMessage("githubUsername config property missing.") + if (githubUsername === undefined || githubUsername === "") { + node.payload.uiObject.setErrorMessage("githubUsername config property missing.") return } + let userProfile = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject( + node, + 'User Profile', + UI.projects.foundations.spaces.designSpace.workspace.workspaceNode.rootNodes + ) + createNewAccount() function createNewAccount() { @@ -62,7 +64,7 @@ function newGovernanceFunctionLibraryProfileConstructor() { params: { method: "signData", privateKey: privateKey, - data: data + data: githubUsername } } @@ -83,11 +85,25 @@ function newGovernanceFunctionLibraryProfileConstructor() { console.log('Call to WEB3 Server failed. ' + response.error) return } - UI.projects.foundations.utilities.nodeConfig.saveConfigProperty(node.payload.referenceParent.payload, 'signature', response.signature) + /* + We store at the User Profile the Signed githubUsername + */ + UI.projects.foundations.utilities.nodeConfig.saveConfigProperty(userProfile.payload, 'signature', response.signature) UI.projects.foundations.utilities.nodeConfig.saveConfigProperty(node.payload, 'address', address) UI.projects.foundations.utilities.nodeConfig.saveConfigProperty(node.payload, 'privateKey', privateKey) - - node.payload.uiObject.setInfoMessage("Profile Account has been successfully created.") + /* + We set the name of the User Profile as the githubUsername + */ + userProfile.name = githubUsername + /* + We also Install the User Profile as a Plugin, which in turns saves it. + */ + userProfile.payload.uiObject.menu.internalClick('Install as Plugin') + userProfile.payload.uiObject.menu.internalClick('Install as Plugin') + /* + Show nice message. + */ + node.payload.uiObject.setInfoMessage("Profile Private Key has been successfully created. User Profile installed as a plugin and saved. Use the Private Key at a crypto wallet and delete this node once done.", 10000) } } }