@@ -317,6 +304,7 @@ export default function RoomInfo(props) {
{user.name}
diff --git a/client/src/components/SidebarSearch/index.js b/client/src/components/SidebarSearch/index.js
index 5a9d398..55bd545 100644
--- a/client/src/components/SidebarSearch/index.js
+++ b/client/src/components/SidebarSearch/index.js
@@ -36,8 +36,8 @@ export default function SidebarSearch(props) {
.then(response => response.json())
.then(data => {
setSearchResults([...data["users"], ...data["rooms"]]);
- }).catch(err => {
- console.log("Error searching rooms --->", err);
+ }).catch(error => {
+ console.log(error);
})
}
diff --git a/client/src/components/SignedLeftSidebar/index.js b/client/src/components/SignedLeftSidebar/index.js
index 3fa12c1..d39f1d0 100644
--- a/client/src/components/SignedLeftSidebar/index.js
+++ b/client/src/components/SignedLeftSidebar/index.js
@@ -203,6 +203,7 @@ export default function SignedLeftSidebar(props) {
break;
}
break;
+ default:
}
};
window.addEventListener("message", handleMessageEvents, true);
@@ -291,7 +292,6 @@ export default function SignedLeftSidebar(props) {
Cookies.remove("rc_uid");
Cookies.remove("rc_token");
Cookies.remove("gh_login_token");
- Cookies.remove("gh_private_repo_token");
window.location = "/login";
})
.catch((err) => {
@@ -443,7 +443,6 @@ export default function SignedLeftSidebar(props) {
handleEndCreateChannel={handleEndCreateChannel}
organizations={organizations}
setSnackbar={setSnackbar}
- addRoom={addRoom}
rooms={rooms["conversations"]}
/>
)}
diff --git a/client/src/utils/constants-example.js b/client/src/utils/constants-example.js
index 7176c4e..99dd462 100644
--- a/client/src/utils/constants-example.js
+++ b/client/src/utils/constants-example.js
@@ -1,18 +1,10 @@
const githubClientID = process.env.GITHUB_CLIENT_ID || "YOUR_GITHUB_CLIENT_ID";
-const githubPrivateRepoAccessClientID =
- process.env.GITHUB_PRIVATE_REPO_ACCESS_CLIENT_ID ||
- "YOUR_GITHUB_PRIVATE_REPO_ACCESS_CLIENT_ID";
const rcApiDomain =
process.env.RC_API_DOMAIN || "YOUR_SELF_HOSTED_RC_API_DOMAIN";
const githubApiDomain =
process.env.GITHUB_API_DOMAIN || "https://api.github.com";
const rc4gitDomain =
- process.env.RC4GIT_DOMAIN || "YOUR_SELF_HOSTED_RC4GIT_CLIENT"
+ process.env.RC4GIT_DOMAIN || "YOUR_SELF_HOSTED_RC4GIT_CLIENT";
+const githubAppSlug = process.env.GITHUB_APP_SLUG || "rcforcommunity";
-export {
- githubClientID,
- githubPrivateRepoAccessClientID,
- rcApiDomain,
- githubApiDomain,
- rc4gitDomain
-};
+export { githubClientID, rcApiDomain, githubApiDomain, rc4gitDomain, githubAppSlug };
diff --git a/server/config/constants_example.js b/server/config/constants_example.js
index 221894f..e9edc0a 100644
--- a/server/config/constants_example.js
+++ b/server/config/constants_example.js
@@ -5,10 +5,6 @@ const iv = process.env.RC_PASS_CIPHER_IV || "YOUR IV";
const githubClientSecret =
process.env.GITHUB_CLIENT_SECRET || "GH CLIENT SECRET";
const githubClientID = process.env.GITHUB_CLIENT_ID || "GH CLIENT ID";
-const githubPrivateRepoAccessClientSecret =
- process.env.githubPrivateRepoAccessClientSecret || "GH CLIENT SECRET 2";
-const githubPrivateRepoAccessClientID =
- process.env.githubPrivateRepoAccessClientID || "GH CLIENT ID 2";
const githubAuthURL = "https://github.com/login/oauth/access_token";
const githubAPIDomain = "https://api.github.com";
const rocketChatDomain = process.env.RC_DOMAIN || "http://localhost:3000";
@@ -16,7 +12,9 @@ const mongodbURI = process.env.MONGODB_URI || "mongodb://127.0.0.1/rc4git";
const rc4gitApiURL =
process.env.RC4GIT_API_URL || "YOUR_PUBLICLY_HOSTED_RC4GIT_API_URL";
const rc_uid = process.env.RC_UID || "ROCKET.CHAT SERVER USER ID FOR STATS";
-const rc_token = process.env.RC_TOKEN || "ROCKET.CHAT SERVER USER TOKEN FOR STATS";
+const rc_token =
+ process.env.RC_TOKEN || "ROCKET.CHAT SERVER USER TOKEN FOR STATS";
+
module.exports = {
jwtSecret,
algorithm,
@@ -28,9 +26,7 @@ module.exports = {
githubAPIDomain,
rocketChatDomain,
mongodbURI,
- githubPrivateRepoAccessClientID,
- githubPrivateRepoAccessClientSecret,
rc4gitApiURL,
rc_uid,
- rc_token
+ rc_token,
};
diff --git a/server/controllers/createChannel.js b/server/controllers/createChannel.js
deleted file mode 100644
index d23e981..0000000
--- a/server/controllers/createChannel.js
+++ /dev/null
@@ -1,75 +0,0 @@
-const axios = require("axios");
-const constants = require("./../config/constants");
-
-module.exports = async function (req, res) {
- try {
- const headers = {
- "X-Auth-Token": req.body.rc_token,
- "X-User-Id": req.body.rc_uid,
- "Content-type": "application/json",
- };
-
- const rcCreateChannelResponse = await axios({
- method: "post",
- url: `${constants.rocketChatDomain}/api/v1/channels.create`,
- headers: headers,
- data: {
- name: req.body.channel,
- members: req.body.members,
- },
- });
-
- const rcSetChannelTopic = await axios({
- method: "post",
- url: `${constants.rocketChatDomain}/api/v1/channels.setTopic`,
- headers: headers,
- data: {
- roomId: rcCreateChannelResponse.data.channel._id,
- topic: req.body.topic,
- },
- });
-
- if (req.body.type === "p") {
- const rcSetChannelType = await axios({
- method: "post",
- url: `${constants.rocketChatDomain}/api/v1/channels.setType`,
- headers: headers,
- data: {
- roomId: rcCreateChannelResponse.data.channel._id,
- type: req.body.type,
- },
- });
- rcCreateChannelResponse.data.channel["type"] =
- rcSetChannelType.data.channel.t;
- }
-
- // Set associated repository in channel custom fields
- await axios({
- method: "post",
- url: `${constants.rocketChatDomain}/api/v1/${
- req.body.type === "p" ? "groups" : "channels"
- }.setCustomFields`,
- headers: headers,
- data: {
- roomId: rcCreateChannelResponse.data.channel._id,
- customFields: {
- github_repository: req.body.channel.replace("_", "/"),
- },
- },
- });
-
- rcCreateChannelResponse.data.channel["topic"] =
- rcSetChannelTopic.data.topic;
-
- return res.status(200).json({
- success: true,
- data: rcCreateChannelResponse.data,
- });
- } catch (err) {
- console.log(err);
- return res.status(500).json({
- success: false,
- error: `Internal Server Error ---> ${err}`,
- });
- }
-};
diff --git a/server/controllers/login.js b/server/controllers/login.js
index 790f902..aee8726 100644
--- a/server/controllers/login.js
+++ b/server/controllers/login.js
@@ -18,14 +18,6 @@ module.exports.createToken = async function (req, res) {
accept: "application/json",
},
});
- //Check for permission scopes
- const scope = ghTokenResponse.data.scope.split(",");
- if (!scope.includes("read:org") || !scope.includes("user:email")) {
- return res.status(401).json({
- success: false,
- error: "More permissions are required",
- });
- }
//Fetch user email from github
const ghUserEmailResponse = await axios({
@@ -149,7 +141,7 @@ module.exports.createToken = async function (req, res) {
success: true,
data: {
rc_token: rcLoginUserResponse.data.data.authToken,
- rc_uid: rcLoginUserResponse.data.data.userId,
+ rc_uid: rcLoginUserResponse.data.data.userId,
rc4git_token: jwt.sign(userData, constants.jwtSecret),
gh_login_token: ghTokenResponse.data.access_token,
},
@@ -163,40 +155,6 @@ module.exports.createToken = async function (req, res) {
}
};
-module.exports.upgradeAccess = async (req, res) => {
- try {
- //Fetch access_token from github
- const requestToken = req.body.code;
- const ghTokenResponse = await axios({
- method: "post",
- url: `${constants.githubAuthURL}?client_id=${constants.githubPrivateRepoAccessClientID}&client_secret=${constants.githubPrivateRepoAccessClientSecret}&code=${requestToken}`,
- headers: {
- accept: "application/json",
- },
- });
- //Check for permission scopes
- const scope = ghTokenResponse.data.scope.split(",");
- if (!scope.includes("repo")) {
- return res.status(401).json({
- success: false,
- error: "Private Repo Access permissions are required",
- });
- }
- return res.status(200).json({
- success: true,
- data: {
- gh_private_repo_token: ghTokenResponse.data.access_token,
- },
- });
- } catch (err) {
- console.log(err);
- return res.status(500).json({
- success: false,
- error: `Internal Server Error ---> ${err}`,
- });
- }
-};
-
module.exports.sso = (req, res) => {
try {
if (req.cookies["rc4git_token"] && req.cookies["rc_token"]) {
diff --git a/server/controllers/roomMembers.js b/server/controllers/roomMembers.js
deleted file mode 100644
index ea6af45..0000000
--- a/server/controllers/roomMembers.js
+++ /dev/null
@@ -1,24 +0,0 @@
-const { rocketChatDomain, rc_uid, rc_token } = require("../config/constants");
-const axios = require("axios");
-module.exports.fetchRoomMembers = async (req, res) => {
- try {
- const roomMembers = await axios({
- method: "get",
- url: `${rocketChatDomain}/api/v1/channels.members`,
- headers: {
- "Content-type": "application/json",
- "X-Auth-Token": `${rc_token}`,
- "X-User-Id": `${rc_uid}`,
- },
- params: {
- roomName: req.query.roomName,
- },
- });
- return res
- .status(200)
- .json({ success: true, data: roomMembers.data.members });
- } catch (err) {
- console.log("ERROR --->", err);
- return res.status(500).json({ success: false, error: err });
- }
-};
diff --git a/server/controllers/rooms.js b/server/controllers/rooms.js
new file mode 100644
index 0000000..fc5a6c6
--- /dev/null
+++ b/server/controllers/rooms.js
@@ -0,0 +1,91 @@
+const axios = require("axios");
+const { rocketChatDomain, rc_uid, rc_token } = require("../config/constants");
+
+module.exports.createRoom = async function (req, res) {
+ try {
+ const headers = {
+ "X-Auth-Token": req.body.rc_token,
+ "X-User-Id": req.body.rc_uid,
+ "Content-type": "application/json",
+ };
+
+ const rcCreateChannelResponse = await axios({
+ method: "post",
+ url: `${rocketChatDomain}/api/v1/${
+ req.body.type === "p" ? "groups" : "channels"
+ }.create`,
+ headers: headers,
+ data: {
+ name: req.body.channel,
+ members: req.body.members,
+ },
+ });
+
+ await axios({
+ method: "post",
+ url: `${rocketChatDomain}/api/v1/${
+ req.body.type === "p" ? "groups" : "channels"
+ }.setTopic`,
+ headers: headers,
+ data: {
+ roomId:
+ rcCreateChannelResponse.data[
+ `${req.body.type === "p" ? "group" : "channel"}`
+ ]._id,
+ topic: req.body.topic,
+ },
+ });
+
+ // Set associated repository in channel custom fields
+ const rcSetCustomFields = await axios({
+ method: "post",
+ url: `${rocketChatDomain}/api/v1/${
+ req.body.type === "p" ? "groups" : "channels"
+ }.setCustomFields`,
+ headers: headers,
+ data: {
+ roomId:
+ rcCreateChannelResponse.data[
+ `${req.body.type === "p" ? "group" : "channel"}`
+ ]._id,
+ customFields: {
+ github_repository: req.body.channel.replace("_", "/"),
+ },
+ },
+ });
+
+ return res.status(200).json({
+ success: true,
+ data: rcSetCustomFields.data,
+ });
+ } catch (err) {
+ console.log(err);
+ return res.status(500).json({
+ success: false,
+ error: `Internal Server Error ---> ${err}`,
+ });
+ }
+};
+
+module.exports.fetchRoomMembers = async (req, res) => {
+ try {
+ const roomMembers = await axios({
+ method: "get",
+ url: `${rocketChatDomain}/api/v1/channels.members`,
+ headers: {
+ "Content-type": "application/json",
+ "X-Auth-Token": `${rc_token}`,
+ "X-User-Id": `${rc_uid}`,
+ },
+ params: {
+ roomName: req.query.roomName,
+ },
+ });
+ return res
+ .status(200)
+ .json({ success: true, data: roomMembers.data.members });
+ } catch (err) {
+ console.log("ERROR --->", err);
+ return res.status(500).json({ success: false, error: err });
+ }
+};
diff --git a/server/controllers/webhooks.js b/server/controllers/webhooks.js
index d7a0350..11c4bf8 100644
--- a/server/controllers/webhooks.js
+++ b/server/controllers/webhooks.js
@@ -90,9 +90,9 @@ module.exports.fetchWebhook = async (req, res) => {
}
// Check if the user is part of the room for which activity subscription is requested
- await axios({
+ const x = await axios({
method: "get",
- url: `${constants.rocketChatDomain}/api/v1/channels.info?roomName=${req.query.room_name}`,
+ url: `${constants.rocketChatDomain}/api/v1/rooms.info?roomName=${req.query.room_name}`,
headers: {
"X-Auth-Token": req.cookies.rc_token || constants.rc_token,
"X-User-Id": req.cookies.rc_uid || constants.rc_uid,
@@ -122,13 +122,13 @@ module.exports.fetchWebhook = async (req, res) => {
module.exports.createGithubWebhook = async (req, res) => {
try {
- if (req.cookies["gh_private_repo_token"]) {
+ if (req.cookies["gh_login_token"]) {
const secret_token =
Math.random().toString(36).slice(2) +
Math.random().toString(36).toUpperCase().slice(2);
const headers = {
accept: "application/vnd.github.v3+json",
- Authorization: `token ${req.cookies["gh_private_repo_token"]}`,
+ Authorization: `token ${req.cookies["gh_login_token"]}`,
};
const config = {
@@ -180,13 +180,13 @@ module.exports.createGithubWebhook = async (req, res) => {
module.exports.updateGithubWebhook = async (req, res) => {
try {
- if (req.cookies["gh_private_repo_token"]) {
+ if (req.cookies["gh_login_token"]) {
const hook = await githubWebhook.findOne({ hook_id: req.body.hook_id });
const secret_token = hook.secret_token;
const headers = {
accept: "application/vnd.github.v3+json",
- Authorization: `token ${req.cookies["gh_private_repo_token"]}`,
+ Authorization: `token ${req.cookies["gh_login_token"]}`,
};
const config = {
@@ -231,10 +231,11 @@ module.exports.updateGithubWebhook = async (req, res) => {
module.exports.deleteGithubWebhook = async (req, res) => {
try {
- if (req.cookies["gh_private_repo_token"]) {
+ if (req.cookies["gh_login_token"]) {
+
const headers = {
accept: "application/vnd.github.v3+json",
- Authorization: `token ${req.cookies["gh_private_repo_token"]}`,
+ Authorization: `token ${req.cookies["gh_login_token"]}`,
};
const ghDeleteWebhookResponse = await axios({
diff --git a/server/routes/index.js b/server/routes/index.js
index d99adbd..32b8a9b 100644
--- a/server/routes/index.js
+++ b/server/routes/index.js
@@ -1,18 +1,16 @@
const { Router } = require("express");
const router = Router();
const loginController = require("../controllers/login");
-const createChannelController = require("../controllers/createChannel");
+const roomsController = require("../controllers/rooms");
const verifyWebhooks = require("../middlewares/verifyWebhooks");
const webhooksController = require("../controllers/webhooks");
const passport = require("passport");
const statsController = require("../controllers/stats");
-const roomMembersController = require("../controllers/roomMembers");
router.post("/login", loginController.createToken);
-router.post("/auth/github/upgrade", loginController.upgradeAccess);
router.post("/sso", loginController.sso);
router.get("/logout", loginController.logout);
-router.post("/createChannel", createChannelController);
+router.post("/createChannel", roomsController.createRoom);
router.post(
"/webhooks/github/events",
verifyWebhooks.verifyGithubWebhook,
@@ -40,6 +38,6 @@ router.delete(
);
router.get("/stats", statsController.fetchStats);
-router.get("/roomMembers", roomMembersController.fetchRoomMembers);
+router.get("/roomMembers", roomsController.fetchRoomMembers);
module.exports = router;