diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 7eedd64..1cab8bc 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,6 +1,6 @@ { "name": "@rwth-acis/las2peer-project-service-frontend", - "version": "0.3.2", + "version": "0.4.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -314,6 +314,19 @@ "@polymer/polymer": "^3.0.0" } }, + "@polymer/paper-checkbox": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@polymer/paper-checkbox/-/paper-checkbox-3.1.0.tgz", + "integrity": "sha512-kXm6yDG1tT8if0XuJ2cc9NF+g8Ev4wG+rnf0a+Sx+O7J6fn1jcnBlYn72FlrfjVjDQZDBFmT6nynhD5PvFw8iQ==", + "requires": { + "@polymer/iron-a11y-keys-behavior": "^3.0.0-pre.26", + "@polymer/iron-checked-element-behavior": "^3.0.0-pre.26", + "@polymer/paper-behaviors": "^3.0.0-pre.27", + "@polymer/paper-ripple": "^3.0.0-pre.26", + "@polymer/paper-styles": "^3.0.0-pre.26", + "@polymer/polymer": "^3.0.0" + } + }, "@polymer/paper-dialog": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/@polymer/paper-dialog/-/paper-dialog-3.0.1.tgz", @@ -1094,9 +1107,9 @@ } }, "core-js": { - "version": "3.22.3", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.22.3.tgz", - "integrity": "sha512-1t+2a/d2lppW1gkLXx3pKPVGbBdxXAkqztvWb1EJ8oF8O2gIGiytzflNiFEehYwVK/t2ryUsGBoOFFvNx95mbg==" + "version": "3.23.3", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.23.3.tgz", + "integrity": "sha512-oAKwkj9xcWNBAvGbT//WiCdOMpb9XQG92/Fe3ABFM/R16BsHgePG00mFOgKf7IsCtfj8tA1kHtf/VwErhriz5Q==" }, "crypto-js": { "version": "4.1.1", @@ -1642,40 +1655,13 @@ }, "las2peer-frontend-statusbar": { "version": "github:rwth-acis/las2peer-frontend-statusbar#19eace61e6fa14ebed452d9646234d88081a455c", - "from": "github:rwth-acis/las2peer-frontend-statusbar#19eace61e6fa14ebed452d9646234d88081a455c", + "from": "github:rwth-acis/las2peer-frontend-statusbar#0.3.6", "requires": { "las2peer-frontend-user-widget": "github:rwth-acis/las2peer-frontend-user-widget#0.3.3", "lit-element": "^2.5.1", "openidconnect-signin": "github:rwth-acis/openidconnect-signin" }, "dependencies": { - "las2peer-frontend-user-widget": { - "version": "github:rwth-acis/las2peer-frontend-user-widget#c8bc9aadc05af298da6a4b35b5f3e6425fcce79e", - "from": "github:rwth-acis/las2peer-frontend-user-widget#0.3.3", - "requires": { - "@polymer/iron-ajax": "^3.0.1", - "@polymer/iron-dropdown": "^3.0.1", - "@polymer/iron-flex-layout": "^3.0.1", - "@polymer/iron-form": "^3.0.1", - "@polymer/iron-icon": "^3.0.1", - "@polymer/iron-icons": "^3.0.1", - "@polymer/iron-list": "^3.0.1", - "@polymer/paper-badge": "^3.0.1", - "@polymer/paper-button": "^3.0.1", - "@polymer/paper-card": "^3.0.1", - "@polymer/paper-dialog": "^3.0.1", - "@polymer/paper-dialog-scrollable": "^3.0.1", - "@polymer/paper-dropdown-menu": "^3.0.1", - "@polymer/paper-icon-button": "^3.0.1", - "@polymer/paper-input": "^3.0.1", - "@polymer/paper-item": "^3.0.1", - "@polymer/paper-spinner": "^3.0.1", - "@polymer/paper-styles": "^3.0.1", - "@polymer/paper-toast": "^3.0.1", - "@polymer/paper-toggle-button": "^3.0.1", - "@webcomponents/webcomponentsjs": "^2.2.1" - } - }, "lit-element": { "version": "2.5.1", "resolved": "https://registry.npmjs.org/lit-element/-/lit-element-2.5.1.tgz", @@ -1693,7 +1679,7 @@ }, "las2peer-frontend-user-widget": { "version": "github:rwth-acis/las2peer-frontend-user-widget#c8bc9aadc05af298da6a4b35b5f3e6425fcce79e", - "from": "github:rwth-acis/las2peer-frontend-user-widget#c8bc9aadc05af298da6a4b35b5f3e6425fcce79e", + "from": "github:rwth-acis/las2peer-frontend-user-widget#0.3.3", "requires": { "@polymer/iron-ajax": "^3.0.1", "@polymer/iron-dropdown": "^3.0.1", @@ -1864,7 +1850,7 @@ } }, "openidconnect-signin": { - "version": "github:rwth-acis/openidconnect-signin#f3ad5e95d3014ca0149615c17a12182de0ede3d3", + "version": "github:rwth-acis/openidconnect-signin#601dc2b4cfe602666538a74f14253bc94f976ee1", "from": "github:rwth-acis/openidconnect-signin", "requires": { "lit-element": "^2.5.1", diff --git a/frontend/package.json b/frontend/package.json index 70718a8..e7eed8f 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "@rwth-acis/las2peer-project-service-frontend", - "version": "0.3.2", + "version": "0.4.0", "description": "Frontend for las2peer project service.", "main": "project-list.js", "module": "project-list.js", @@ -21,6 +21,7 @@ "@polymer/iron-icons": "^3.0.1", "@polymer/paper-button": "^3.0.1", "@polymer/paper-card": "^3.0.1", + "@polymer/paper-checkbox": "^3.1.0", "@polymer/paper-dialog": "^3.0.1", "@polymer/paper-dropdown-menu": "^3.1.0", "@polymer/paper-input": "^3.2.1", diff --git a/frontend/project-list.js b/frontend/project-list.js index c5c4660..84f6965 100644 --- a/frontend/project-list.js +++ b/frontend/project-list.js @@ -10,6 +10,7 @@ import '@polymer/paper-listbox/paper-listbox.js'; import '@polymer/paper-tabs'; import '@polymer/iron-icon/iron-icon.js'; import '@polymer/iron-icons/social-icons.js'; +import '@polymer/paper-checkbox/paper-checkbox.js'; import OnlineUserListHelper from './util/online-user-list-helper' import Auth from './util/auth'; @@ -205,7 +206,8 @@ export class ProjectList extends LitElement { */ projectOptionsSelected: { type: Object - } + }, + connectChannelVisible: { type: Boolean } }; } @@ -225,6 +227,7 @@ export class ProjectList extends LitElement { this.disableAllProjects = false; this.yjsAddress = "http://127.0.0.1:1234"; this.yjsResourcePath = "./socket.io"; + this.connectChannelVisible = false; } connectedCallback() { @@ -378,6 +381,14 @@ export class ProjectList extends LitElement { `)} +
+ this.connectChannelVisible = e.target.checked} >Connect to chat channel +
+ + or: + Create new channel +
+
Cancel Create @@ -733,6 +744,23 @@ export class ProjectList extends LitElement { "linkedGroup": linkedGroup, "users": users }; + + // check if project should be linked to chat channel + const connectChannel = this.shadowRoot.getElementById("cb-connect-channel").checked; + const chatInfo = { + connectChannel, + newChannel: false + }; + if(connectChannel) { + // check if new channel should be created + const newChannel = this.shadowRoot.getElementById("cb-create-new-channel").checked; + chatInfo.newChannel = newChannel; + if(!newChannel) { + chatInfo.channelName = this.shadowRoot.getElementById("input-channel-name").value; + } + } + body.chatInfo = chatInfo; + if(GitHub.gitHubUsernameStored()) { body.gitHubUsername = GitHub.getGitHubUsername(); } diff --git a/gradle.properties b/gradle.properties index 23799a4..53991d2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ core.version=1.2.2 service.name=i5.las2peer.services.projectService service.class=ProjectService -service.version=1.1.0 +service.version=1.1.1 java.version=17 las2peer_user1.name=alice diff --git a/project_service/src/main/java/i5/las2peer/services/projectService/ProjectService.java b/project_service/src/main/java/i5/las2peer/services/projectService/ProjectService.java index a170d59..2e20f2b 100644 --- a/project_service/src/main/java/i5/las2peer/services/projectService/ProjectService.java +++ b/project_service/src/main/java/i5/las2peer/services/projectService/ProjectService.java @@ -241,9 +241,11 @@ public Response postProject(@PathParam("system") String system, String inputProj Project project; String creatorGitHubUsername = null; + JSONObject bodyJSON; + try { project = new Project(agent, inputProject); - JSONObject bodyJSON = (JSONObject) JSONValue.parseWithException(inputProject); + bodyJSON = (JSONObject) JSONValue.parseWithException(inputProject); if(bodyJSON.containsKey("gitHubUsername")) { creatorGitHubUsername = (String) bodyJSON.get("gitHubUsername"); } @@ -296,12 +298,27 @@ public Response postProject(@PathParam("system") String system, String inputProj } } - // check if chat channel should be created - if(this.systemsConfig.isChannelCreationEnabled(system)) { - ChatManager chatManager = this.systemsConfig.getChatManager(system); - JSONObject chatInfo = chatManager.createProjectChannel(project, system); - if(chatInfo != null) { - project.setChatInfo(chatInfo); + // check if chat channel connection is enabled for the system + if(this.systemsConfig.isChannelConnectionEnabled(system)) { + // check if channel should be linked for the new project + JSONObject bodyChatInfo = (JSONObject) bodyJSON.get("chatInfo"); + boolean connectChannel = (boolean) bodyChatInfo.get("connectChannel"); + if(connectChannel) { + ChatManager chatManager = this.systemsConfig.getChatManager(system); + JSONObject chatInfo; + + boolean newChannel = (boolean) bodyChatInfo.get("newChannel"); + if (newChannel) { + chatInfo = chatManager.createProjectChannel(project, system); + } else { + // use existing channel + String channelName = (String) bodyChatInfo.get("channelName"); + chatInfo = chatManager.getChannelInfoForExistingChannel(channelName); + } + + if (chatInfo != null) { + project.setChatInfo(chatInfo); + } } } diff --git a/project_service/src/main/java/i5/las2peer/services/projectService/chat/ChatManager.java b/project_service/src/main/java/i5/las2peer/services/projectService/chat/ChatManager.java index 1a5e619..6eebee2 100644 --- a/project_service/src/main/java/i5/las2peer/services/projectService/chat/ChatManager.java +++ b/project_service/src/main/java/i5/las2peer/services/projectService/chat/ChatManager.java @@ -16,5 +16,6 @@ public ChatManager(ChatConfig config) { } public abstract JSONObject createProjectChannel(Project project, String systemName); + public abstract JSONObject getChannelInfoForExistingChannel(String channelName); } diff --git a/project_service/src/main/java/i5/las2peer/services/projectService/chat/RocketChatManager.java b/project_service/src/main/java/i5/las2peer/services/projectService/chat/RocketChatManager.java index c65a055..f055f48 100644 --- a/project_service/src/main/java/i5/las2peer/services/projectService/chat/RocketChatManager.java +++ b/project_service/src/main/java/i5/las2peer/services/projectService/chat/RocketChatManager.java @@ -45,6 +45,34 @@ public JSONObject createProjectChannel(Project project, String systemName) { return channelInfo; } + @Override + public JSONObject getChannelInfoForExistingChannel(String channelName) { + String channelId = getChannelIdByName(channelName); + JSONObject channelInfo = new JSONObject(); + channelInfo.put("type", "RocketChat"); + channelInfo.put("url", getConfig().getUrl()); + channelInfo.put("channelId", channelId); + channelInfo.put("chatUrl", getConfig().getUrl() + "/channel/" + channelId); + return channelInfo; + } + + private String getChannelIdByName(String channelName) { + HttpResponse response = Unirest.get(getConfig().getUrl() + "/api/v1/channels.info") + .header("X-Auth-Token", getConfig().getBotAuthToken()) + .header("X-User-Id", getConfig().getBotUserId()) + .queryString("roomName", channelName) + .asString(); + + if(!response.isSuccess()) { + System.out.println("RocketChat channel info request failed."); + return null; + } + + JSONObject res = (JSONObject) JSONValue.parse(response.getBody()); + JSONObject resChannel = (JSONObject) res.get("channel"); + return (String) resChannel.get("_id"); + } + private RocketChatConfig getConfig() { return (RocketChatConfig) this.config; } diff --git a/project_service/src/main/java/i5/las2peer/services/projectService/util/ProjectServiceSystem.java b/project_service/src/main/java/i5/las2peer/services/projectService/util/ProjectServiceSystem.java index 683d4af..ab1ee26 100644 --- a/project_service/src/main/java/i5/las2peer/services/projectService/util/ProjectServiceSystem.java +++ b/project_service/src/main/java/i5/las2peer/services/projectService/util/ProjectServiceSystem.java @@ -122,7 +122,7 @@ public RocketChatConfig getRocketChatConfig() { return rocketChatConfig; } - public boolean isChannelCreationEnabled() { + public boolean isChannelConnectionEnabled() { return this.rocketChatConfig != null; } diff --git a/project_service/src/main/java/i5/las2peer/services/projectService/util/SystemsConfig.java b/project_service/src/main/java/i5/las2peer/services/projectService/util/SystemsConfig.java index f393dcd..bf0772f 100644 --- a/project_service/src/main/java/i5/las2peer/services/projectService/util/SystemsConfig.java +++ b/project_service/src/main/java/i5/las2peer/services/projectService/util/SystemsConfig.java @@ -94,9 +94,9 @@ public String getGitHubPATBySystem(String systemName) { return null; } - public boolean isChannelCreationEnabled(String systemName) { + public boolean isChannelConnectionEnabled(String systemName) { for(ProjectServiceSystem system : this.systems) { - if(system.getName().equals(systemName)) return system.isChannelCreationEnabled(); + if(system.getName().equals(systemName)) return system.isChannelConnectionEnabled(); } return false; }