diff --git a/client/public/index.html b/client/public/index.html index e51a136..37bedb3 100644 --- a/client/public/index.html +++ b/client/public/index.html @@ -20,7 +20,7 @@ work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> - RC4Community + RCforCommunity diff --git a/client/src/components/ActivityPane/index.js b/client/src/components/ActivityPane/index.js index e394662..99f3995 100644 --- a/client/src/components/ActivityPane/index.js +++ b/client/src/components/ActivityPane/index.js @@ -5,10 +5,7 @@ import ActivityItem from "./../ActivityItem"; import MuiAlert from "@material-ui/lab/Alert"; import { Snackbar } from "@material-ui/core"; import ConfigureWebhook from "../ConfigureWebhook"; -import { - githubPrivateRepoAccessClientID, - githubApiDomain, -} from "../../utils/constants"; +import { githubApiDomain } from "../../utils/constants"; import { IoSettingsOutline } from "react-icons/io5"; import "./index.css"; @@ -81,14 +78,12 @@ export default function ActivityPane(props) { const repository = props.location.pathname .split("/")[2] .replace("_", "/"); - const authToken = - Cookies.get("gh_private_repo_token") || - Cookies.get("gh_login_token"); + const authToken = Cookies.get("gh_login_token"); const ghRepoResponse = await axios({ method: "get", url: `${githubApiDomain}/repos/${repository}`, headers: { - accept: "application/json", + accept: "application/vnd.github.v3+json", Authorization: `token ${authToken}`, }, }); @@ -98,7 +93,7 @@ export default function ActivityPane(props) { } catch (error) { console.log(error); } - } + }; checkIfUserIsOwner(); // eslint-disable-next-line }, [props.location.pathname]); @@ -118,15 +113,6 @@ export default function ActivityPane(props) { } }, [webhookId]); - const handleClickConfigureWebhooks = async () => { - if (!Cookies.get("gh_private_repo_token")) { - Cookies.set("gh_upgrade_prev_path", window.location.pathname); - window.location.href = `https://github.com/login/oauth/authorize?scope=repo&client_id=${githubPrivateRepoAccessClientID}`; - } else { - setOpenWebhookDialog(true); - } - }; - const setSnackbar = (snackbarSeverity, snackbarText) => { setSnackbarSeverity(snackbarSeverity); setSnackbarText(snackbarText); @@ -143,14 +129,14 @@ export default function ActivityPane(props) { return (
-
+
Activity {authState.isLoggedIn && isRepoOwner && (
setOpenWebhookDialog(true)} />
)} @@ -164,10 +150,10 @@ export default function ActivityPane(props) {
)} {webhookId && - events.map((event) => { + events.map((event, index) => { return ( diff --git a/client/src/components/App.js b/client/src/components/App.js index 86695bd..75f0e59 100644 --- a/client/src/components/App.js +++ b/client/src/components/App.js @@ -71,8 +71,8 @@ export default class App extends React.Component { stats: data.data }) }) - .catch((err) => { - console.log("Error logging out --->", err); + .catch((error) => { + console.log(error); return; }); } diff --git a/client/src/components/ChatWindow/index.js b/client/src/components/ChatWindow/index.js index 68d00f3..34fab22 100644 --- a/client/src/components/ChatWindow/index.js +++ b/client/src/components/ChatWindow/index.js @@ -16,7 +16,7 @@ export default function ChatWindow(props) { { externalCommand: "go", path: `${pathname}/?layout=embedded` }, `${rcApiDomain}` ); - }, [pathname]); + }, [props.location]); return (
{ - const { publicRepositories, privateRepositories } = this.state; - - //Fetch public repositories - const publicRepoResponse = await axios({ + const getAllInstallations = await axios({ method: "get", - url: `https://api.github.com/user/repos?visibility=public&affiliation=owner,organization_member`, + url: `https://api.github.com/user/installations`, headers: { accept: "application/json", Authorization: `token ${Cookies.get("gh_login_token")}`, @@ -62,73 +55,50 @@ export default class CreateChannel extends Component { per_page: 100, }, }); - publicRepoResponse.data.map((repository) => - publicRepositories.push(repository.full_name) - ); - - if (Cookies.get("gh_private_repo_token")) { - const privateRepoResponse = await axios({ + let repositories = []; + for (const installation of getAllInstallations.data.installations) { + const fetchReposResponse = await axios({ method: "get", - url: `https://api.github.com/user/repos?visibility=private&affiliation=owner,organization_member`, + url: `https://api.github.com/user/installations/${installation.id}/repositories`, headers: { accept: "application/json", - Authorization: `token ${Cookies.get("gh_private_repo_token")}`, + Authorization: `token ${Cookies.get("gh_login_token")}`, }, params: { per_page: 100, }, }); - privateRepoResponse.data.map((repository) => - privateRepositories.push(repository.full_name) - ); - } - this.setState({ repositories: publicRepositories }); - }; - - handleAllRepositories = async (event) => { - const { publicRepositories, privateRepositories } = this.state; - this.setState({ ...this.state, [event.target.name]: event.target.checked }); - if (event.target.checked) { - if (!Cookies.get("gh_private_repo_token")) { - Cookies.set("gh_upgrade_prev_path", window.location.pathname); - window.location.href = `https://github.com/login/oauth/authorize?scope=repo&client_id=${githubPrivateRepoAccessClientID}`; - } - this.setState({ - repositories: publicRepositories.concat(privateRepositories), + fetchReposResponse.data.repositories.forEach((repo) => { + repositories.push(repo.full_name); }); - } else { - this.setState({ repositories: publicRepositories }); } + + this.setState({ repositories }); }; handleCreateChannel = async () => { const { channel, publicChannel } = this.state; - const { setSnackbar, addRoom } = this.props; - const authToken = - Cookies.get("gh_private_repo_token") || Cookies.get("gh_login_token"); + const { setSnackbar } = this.props; + const authToken = Cookies.get("gh_login_token"); let collaborators = [], description = ""; this.setState({ loading: true }); //Populate collaborators for the repo try { - // Fetching collaborators requires repo scope - if (Cookies.get("gh_private_repo_token")) { - const ghCollaboratorsResponse = await axios({ - method: "get", - url: `https://api.github.com/repos/${channel}/collaborators`, - headers: { - accept: "application/json", - Authorization: `token ${authToken}`, - }, - params: { - per_page: 100, - }, - }); - ghCollaboratorsResponse.data.map((member) => - collaborators.push(member.login.concat("_github_rc4git")) - ); - } - + const ghCollaboratorsResponse = await axios({ + method: "get", + url: `https://api.github.com/repos/${channel}/collaborators`, + headers: { + accept: "application/json", + Authorization: `token ${authToken}`, + }, + params: { + per_page: 100, + }, + }); + ghCollaboratorsResponse.data.map((member) => + collaborators.push(member.login) + ); const ghRepoResponse = await axios({ method: "get", url: `https://api.github.com/repos/${channel}`, @@ -138,9 +108,7 @@ export default class CreateChannel extends Component { }, }); - description = ghRepoResponse.data.description - ? ghRepoResponse.data.description - : ""; + description = ghRepoResponse.data.description || ""; const rcCreateChannelResponse = await axios({ method: "post", @@ -154,7 +122,7 @@ export default class CreateChannel extends Component { type: publicChannel ? "c" : "p", }, }); - if (rcCreateChannelResponse.data.data.success) { + if (publicChannel) { let room = rcCreateChannelResponse.data.data.channel; //Add embeddable code for room to description description = description.concat(` @@ -180,19 +148,18 @@ Embed this room description: description, }, }); - - addRoom(room); - setSnackbar(true, "success", "Room created successfully!"); this.setState({ loading: false, - room: room, openCreateChannelDialog: false, showEmbedBadgeDialog: true, }); } else { - this.setState({ loading: false }); - setSnackbar(true, "error", "Error Creating Room!"); + this.setState({ + loading: false, + openCreateChannelDialog: false, + }); } + setSnackbar(true, "success", "Room created successfully!"); } catch (error) { console.log(error); this.setState({ loading: false }); @@ -204,10 +171,8 @@ Embed this room const { repositories, publicChannel, - includePrivateRepositories, channel, loading, - room, openCreateChannelDialog, showEmbedBadgeDialog, } = this.state; @@ -232,7 +197,15 @@ Embed this room


-

Select Repository

+

+ Select Repository{" "} + + Add/Remove Repositories + +

)} -
-
-

Show All Repositories

- - } - /> -
- -

- {includePrivateRepositories - ? "Both public and private " - : "Only public "} - repositories are visible. -

-

Public Room


+

Note:

+ {publicChannel && ( +

+ Public room for a private repository may expose the metadata + of that repository. +

+ )} +

+ All the repository collaborators who are RCforCommunity users as + well will automatically get added in the chat room. +

+
@@ -126,12 +127,13 @@ export default function Home(props) { search Discover existing rooms
- + community ); diff --git a/client/src/components/Login/index.js b/client/src/components/Login/index.js index 9b787eb..21da656 100644 --- a/client/src/components/Login/index.js +++ b/client/src/components/Login/index.js @@ -63,7 +63,7 @@ export default function Login(props) { return (
- + RC-logo
@@ -80,7 +80,7 @@ export default function Login(props) { ) : ( Login with github @@ -88,10 +88,6 @@ export default function Login(props) { )}
- {"By proceeding you are agreeing to our "} - Terms of Service,{" "} - Privacy Policy and{" "} - Legal Notice.
{"Powered by "}{" "} diff --git a/client/src/components/MainLayout/index.js b/client/src/components/MainLayout/index.js index 670c1eb..ba87bbc 100644 --- a/client/src/components/MainLayout/index.js +++ b/client/src/components/MainLayout/index.js @@ -8,36 +8,6 @@ import RightSidebar from "./../RightSidebar"; import "./index.css"; export default function MainLayout(props) { - useEffect(() => { - const url = window.location.href; - const hasCode = url.includes("?code="); - - const proxy_url = `/api/auth/github/upgrade`; - - // If Github API returns the code parameter - if (hasCode) { - const newUrl = url.split("?code="); - - const requestData = { - code: newUrl[1], - }; - - fetch(proxy_url, { - method: "POST", - body: JSON.stringify(requestData), - headers: { - "Content-Type": "application/json", - }, - }) - .then((response) => response.json()) - .then((data) => { - Cookies.set("gh_private_repo_token", data.data.gh_private_repo_token); - window.location.href = - window.location.origin + Cookies.get("gh_upgrade_prev_path"); - }) - .catch((error) => console.log(error)); - } - }); const {authState, stats} = props; diff --git a/client/src/components/RoomInfo/index.js b/client/src/components/RoomInfo/index.js index c79e9de..5468608 100644 --- a/client/src/components/RoomInfo/index.js +++ b/client/src/components/RoomInfo/index.js @@ -56,7 +56,6 @@ function a11yProps(index) { export default function RoomInfo(props) { const [repoInfo, setRepoInfo] = useState({}); const [isPrivate, setIsPrivate] = useState(false); - const [issuesCount, setIssuesCount] = useState(0); const [isNotAccessible, setIsNotAccessible] = useState(false); const [roomMembers, setRoomMembers] = useState([]); const [openMembersDialog, setOpenMembersDialog] = useState(false); @@ -77,28 +76,14 @@ export default function RoomInfo(props) { .split("/")[2] .replace("_", "/"); const headers = { - accept: "application/json", + accept: "application/vnd.github.v3+json", + Authorization: `Token ${Cookies.get("gh_login_token")}`, }; - if (Cookies.get("gh_private_repo_token")) { - headers["Authorization"] = `token ${Cookies.get( - "gh_private_repo_token" - )}`; - } const ghRepoInfoResponse = await axios({ method: "get", url: `${githubApiDomain}/repos/${repository}`, headers: headers, }); - const ghIssuesResponse = await axios({ - method: "get", - url: `${githubApiDomain}/repos/${repository}/issues`, - headers: headers, - }); - // GitHub treats both PRs and issues as issues except that PRs can be - // distinguished by the presence of a pull_request key - setIssuesCount( - ghIssuesResponse.data.filter((issue) => !issue.pull_request).length - ); setRepoInfo(ghRepoInfoResponse.data); } catch (error) { console.log(error); @@ -162,6 +147,7 @@ export default function RoomInfo(props) { }; ghRepoInfo(); fetchRoomMembers(); + // eslint-disable-next-line }, [props.location.pathname]); const handleChange = (event, newValue) => { @@ -208,10 +194,11 @@ export default function RoomInfo(props) { xs={2} className="online-users-grid-item" > - + online {user.username} ); @@ -257,11 +244,11 @@ export default function RoomInfo(props) {
- {issuesCount} issues + {repoInfo.open_issues_count} issues @@ -317,6 +304,7 @@ export default function RoomInfo(props) { {user.username}
{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;