From 3b68cc9a1a015574d7965dc071aa449bd4db5d57 Mon Sep 17 00:00:00 2001 From: r1bb3t Date: Wed, 18 Jul 2018 14:36:03 -0700 Subject: [PATCH 1/6] started adding black list to server side rather than front end --- config/ews/room-blacklist.js | 5 +++++ config/ews/rooms.js | 35 +++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 config/ews/room-blacklist.js diff --git a/config/ews/room-blacklist.js b/config/ews/room-blacklist.js new file mode 100644 index 0000000..81f5e58 --- /dev/null +++ b/config/ews/room-blacklist.js @@ -0,0 +1,5 @@ +module.exports = { + 'roomEmails' : [ + 'ROOM_EMAIL@DOMAIN.com' + ] +}; diff --git a/config/ews/rooms.js b/config/ews/rooms.js index 66b1721..6e35d8c 100644 --- a/config/ews/rooms.js +++ b/config/ews/rooms.js @@ -3,6 +3,7 @@ module.exports = function (callback) { // modules ------------------------------------------------------------------- var ews = require("ews-javascript-api"); var auth = require("../auth.js"); + var blacklist = require("../room-blacklist.js"); // ews ----------------------------------------------------------------------- var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2016); @@ -30,22 +31,28 @@ module.exports = function (callback) { roomLists.forEach(function (item, i, array) { exch.GetRooms(new ews.Mailbox(item.Address)).then((rooms) => { rooms.forEach(function (roomItem, roomIndex, roomsArray) { - var room = {}; + let room = {}; + // if the email addresses != your corporate domain, // replace email domain with domain - var email = roomItem.Address; + let email = roomItem.Address; email = email.substring(0, email.indexOf('@')); email = email + '@' + auth.domain; - var roomAlias = roomItem.Name.toLowerCase().replace(/\s+/g, "-"); + // use either email var or roomItem.Address - depending on your use case + let inBlacklist = isRoomInBlacklist(email); - room.Roomlist = item.Name; - room.Name = roomItem.Name; - room.RoomAlias = roomAlias; - room.Email = email; - roomAddresses.push(room); + // if not in blacklist, proceed as normal; otherwise, skip + if (!inBlacklist) { + let roomAlias = roomItem.Name.toLowerCase().replace(/\s+/g, "-"); + room.Roomlist = item.Name; + room.Name = roomItem.Name; + room.RoomAlias = roomAlias; + room.Email = email; + roomAddresses.push(room); + } }); counter++; @@ -107,7 +114,7 @@ module.exports = function (callback) { fillRoomData(context, room, response.Items); }, (error) => { // handle the error here -// callback(error, null); + // callback(error, null); fillRoomData(context, room, undefined, { errorMessage: error.response.errorMessage }); }); }); @@ -115,6 +122,11 @@ module.exports = function (callback) { return promise; }; + // check if room is in blacklist + function isRoomInBlacklist(email) { + return blacklist.roomEmails.includes(email); + } + // do all of the process for the appointment times function processTime(appointmentTime) { var time = JSON.stringify(appointmentTime); @@ -136,13 +148,12 @@ module.exports = function (callback) { return 0; //default return value (no sorting) } + + // perform promise chain to get rooms getListOfRooms() .then(getRoomsInLists) .then(getAppointmentsForRooms) .then(function(rooms){ callback(null, rooms); }); - - - }; From 9b0240b8ae39d62c4c4eb100774d4deb826ed5f7 Mon Sep 17 00:00:00 2001 From: r1bb3t Date: Wed, 18 Jul 2018 18:01:55 -0700 Subject: [PATCH 2/6] adjusted location of blacklist loop --- config/ews/rooms.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/config/ews/rooms.js b/config/ews/rooms.js index 6e35d8c..4d77534 100644 --- a/config/ews/rooms.js +++ b/config/ews/rooms.js @@ -31,20 +31,19 @@ module.exports = function (callback) { roomLists.forEach(function (item, i, array) { exch.GetRooms(new ews.Mailbox(item.Address)).then((rooms) => { rooms.forEach(function (roomItem, roomIndex, roomsArray) { - let room = {}; - - - // if the email addresses != your corporate domain, - // replace email domain with domain - let email = roomItem.Address; - email = email.substring(0, email.indexOf('@')); - email = email + '@' + auth.domain; - // use either email var or roomItem.Address - depending on your use case - let inBlacklist = isRoomInBlacklist(email); + let inBlacklist = isRoomInBlacklist(roomItem.Address); // if not in blacklist, proceed as normal; otherwise, skip if (!inBlacklist) { + let room = {}; + + // if the email addresses != your corporate domain, + // replace email domain with domain + let email = roomItem.Address; + email = email.substring(0, email.indexOf('@')); + email = email + '@' + auth.domain; + let roomAlias = roomItem.Name.toLowerCase().replace(/\s+/g, "-"); room.Roomlist = item.Name; From 4fe6747dc2668914928c5a95ef1b850fefef6da7 Mon Sep 17 00:00:00 2001 From: r1bb3t Date: Wed, 18 Jul 2018 18:11:41 -0700 Subject: [PATCH 3/6] updated require reference --- config/ews/rooms.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/ews/rooms.js b/config/ews/rooms.js index 4d77534..bc6912d 100644 --- a/config/ews/rooms.js +++ b/config/ews/rooms.js @@ -3,7 +3,7 @@ module.exports = function (callback) { // modules ------------------------------------------------------------------- var ews = require("ews-javascript-api"); var auth = require("../auth.js"); - var blacklist = require("../room-blacklist.js"); + var blacklist = require("./room-blacklist.js"); // ews ----------------------------------------------------------------------- var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2016); From 572c7ab8339af6d2a2f40ea3549a4d73c8c647ae Mon Sep 17 00:00:00 2001 From: r1bb3t Date: Wed, 18 Jul 2018 18:30:55 -0700 Subject: [PATCH 4/6] moved files and updated paths in respective files --- {config => app}/ews/roomlists.js | 2 +- {config => app}/ews/rooms.js | 4 ++-- app/routes.js | 4 ++-- config/controller.js => app/socket-controller.js | 0 config/{ews => }/room-blacklist.js | 0 server.js | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) rename {config => app}/ews/roomlists.js (94%) rename {config => app}/ews/rooms.js (97%) rename config/controller.js => app/socket-controller.js (100%) rename config/{ews => }/room-blacklist.js (100%) diff --git a/config/ews/roomlists.js b/app/ews/roomlists.js similarity index 94% rename from config/ews/roomlists.js rename to app/ews/roomlists.js index 5a7e143..59e4fa3 100644 --- a/config/ews/roomlists.js +++ b/app/ews/roomlists.js @@ -2,7 +2,7 @@ module.exports = function (callback) { // modules ------------------------------------------------------------------- var ews = require("ews-javascript-api"); - var auth = require("../auth.js"); + var auth = require("../../config/auth.js"); // ews ----------------------------------------------------------------------- var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2016); diff --git a/config/ews/rooms.js b/app/ews/rooms.js similarity index 97% rename from config/ews/rooms.js rename to app/ews/rooms.js index bc6912d..80624aa 100644 --- a/config/ews/rooms.js +++ b/app/ews/rooms.js @@ -2,8 +2,8 @@ module.exports = function (callback) { // modules ------------------------------------------------------------------- var ews = require("ews-javascript-api"); - var auth = require("../auth.js"); - var blacklist = require("./room-blacklist.js"); + var auth = require("../../config/auth.js"); + var blacklist = require("../../config/room-blacklist.js"); // ews ----------------------------------------------------------------------- var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2016); diff --git a/app/routes.js b/app/routes.js index f9a8a65..a7ee307 100644 --- a/app/routes.js +++ b/app/routes.js @@ -5,7 +5,7 @@ module.exports = function(app) { // returns an array of room objects app.get('/api/rooms', function(req, res) { - var ews = require('../config/ews/rooms.js'); + var ews = require('./ews/rooms.js'); ews(function(err, rooms) { res.json(rooms); @@ -15,7 +15,7 @@ module.exports = function(app) { // returns an array of roomlist objects app.get('/api/roomlists', function(req, res) { - var ews = require('../config/ews/roomlists.js'); + var ews = require('./ews/roomlists.js'); ews(function(err, roomlists) { res.json(roomlists); diff --git a/config/controller.js b/app/socket-controller.js similarity index 100% rename from config/controller.js rename to app/socket-controller.js diff --git a/config/ews/room-blacklist.js b/config/room-blacklist.js similarity index 100% rename from config/ews/room-blacklist.js rename to config/room-blacklist.js diff --git a/server.js b/server.js index a4f5a75..76d2550 100644 --- a/server.js +++ b/server.js @@ -20,8 +20,8 @@ var theserver = app.listen(port, function(){ var io = require('socket.io').listen(theserver); // controller if using room lists - var controller = require('./config/controller.js')(io); + var controller = require('./app/socket-controller.js')(io); // log something so we know the server is working correctly - console.log('now we are cooking.'); + console.log(`now we're cooking.`); }); From 0e6ef6c931a91bd19db96fefe9be0398eff25410 Mon Sep 17 00:00:00 2001 From: r1bb3t Date: Wed, 18 Jul 2018 18:36:44 -0700 Subject: [PATCH 5/6] remove front end handling of room-blacklist --- .../components/flightboard/FlightboardRow.js | 138 ++++++++---------- ui-react/src/config/flightboard.config.js | 3 - 2 files changed, 61 insertions(+), 80 deletions(-) diff --git a/ui-react/src/components/flightboard/FlightboardRow.js b/ui-react/src/components/flightboard/FlightboardRow.js index eb24b0c..7f5e52d 100644 --- a/ui-react/src/components/flightboard/FlightboardRow.js +++ b/ui-react/src/components/flightboard/FlightboardRow.js @@ -8,8 +8,7 @@ class FlightboardRow extends Component { super(props); this.state = { nextUp: '', - timesPresent: false, - skippedRoom: false + timesPresent: false } } @@ -32,25 +31,12 @@ class FlightboardRow extends Component { } } - isRoomSkipped = () => { - const { item } = this.props; - - fbConfig.board.roomsToSkip.forEach(function(configItem, configKey) { - if(configItem === item.Email) { - this.setState({ - skippedRoom: true - }); - } - }); - } - componentDidMount = () => { - this.isRoomSkipped(); this.getAppointmentTime(); } render() { - const { nextUp, skippedRoom, timesPresent } = this.state; + const { nextUp, timesPresent } = this.state; const { item, now } = this.props; const styles = { @@ -62,79 +48,77 @@ class FlightboardRow extends Component { const room = item.Name.toLowerCase().replace(/\s+/g, "-"); const roomlist = 'roomlist-' + item.Roomlist.toLowerCase().replace(/\s+/g, "-"); - // if the room needs to be skipped, return null - if (!skippedRoom) { - let meetingRoomClass = `${ room } meeting-room ${ item.Busy ? 'meeting-room-busy' : '' }`; - meetingRoomClass += item.Busy ? ' meeting-room-busy' : ''; - meetingRoomClass += item.ErrorMessage ? ' meeting-room-error' : ''; - const meetingClass = item.ErrorMessage - ? 'meeting-error' - : item.Busy - ? 'meeting-busy' - : 'meeting-open'; - let statusText = item.ErrorMessage - ? fbConfig.board.text.statusError - : item.Busy - ? fbConfig.board.text.statusBusy - : fbConfig.board.text.statusAvailable; + // set row class based on meet room status + let meetingRoomClass = `${ room } meeting-room ${ item.Busy ? 'meeting-room-busy' : '' }`; + meetingRoomClass += item.Busy ? ' meeting-room-busy' : ''; + meetingRoomClass += item.ErrorMessage ? ' meeting-room-error' : ''; + const meetingClass = item.ErrorMessage + ? 'meeting-error' + : item.Busy + ? 'meeting-busy' + : 'meeting-open'; + let statusText = item.ErrorMessage + ? fbConfig.board.text.statusError + : item.Busy + ? fbConfig.board.text.statusBusy + : fbConfig.board.text.statusAvailable; - return ( -
-
-
-
-
-
-
- {statusText} -
+ return ( +
+
+
+
+
+
+
+ {statusText}
-
-
- {item.Name} -
+
+
+
+ {item.Name} +
+
+
+
+ {timesPresent && item.Appointments[0].End >= now && +
+ + {nextUp} + + + {item.Appointments[0].Subject} + +
+ }
-
-
- {timesPresent && item.Appointments[0].End >= now && -
- - {nextUp} - - - {item.Appointments[0].Subject} - -
- } -
-
- {timesPresent ? - new Date(parseInt(item.Appointments[0].Start, 10)).toLocaleTimeString([], {hour: '2-digit', minute: '2-digit'}) + ' - ' + new Date(parseInt(item.Appointments[0].End, 10)).toLocaleTimeString([], {hour: '2-digit', minute: '2-digit'}) - : '' - } -
-
- {timesPresent && item.Appointments[0].End >= now && - item.Appointments[0].Organizer - } -
+
+ {timesPresent ? + new Date(parseInt(item.Appointments[0].Start, 10)).toLocaleTimeString([], {hour: '2-digit', minute: '2-digit'}) + ' - ' + new Date(parseInt(item.Appointments[0].End, 10)).toLocaleTimeString([], {hour: '2-digit', minute: '2-digit'}) + : '' + }
-
-
+
+ {timesPresent && item.Appointments[0].End >= now && + item.Appointments[0].Organizer + } +
+
+
+
- - - + + + -
- ) - } +
+ ) } } diff --git a/ui-react/src/config/flightboard.config.js b/ui-react/src/config/flightboard.config.js index d623856..2124866 100644 --- a/ui-react/src/config/flightboard.config.js +++ b/ui-react/src/config/flightboard.config.js @@ -1,8 +1,5 @@ module.exports = { 'board' : { - 'roomsToSkip' : [ - 'ROOM_EMAIL@DOMAIN.com' - ], 'text' : { 'nextUp' : 'Next Up', 'statusAvailable' : 'Open', From 373e10672a702d0244e1243da8d5229b074435cc Mon Sep 17 00:00:00 2001 From: r1bb3t Date: Wed, 18 Jul 2018 18:46:39 -0700 Subject: [PATCH 6/6] updated readme to reflect 0.3.1 changes --- README.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1142446..c106fe6 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ In the event of wanting to commercially distribute a closed source modification ## Updates +* v0.3.1 + * Removed skipped rooms/room blacklist filtering from front end to back end. * v0.3 * Cleaned up unnecessarily nested component folder structure * [#8](https://github.com/danxfisher/MeetEasier/pull/8) - add script-shortcuts to `package.json` in root @@ -163,13 +165,27 @@ There are three main directories in the `ui-react/src/` folder: ```javascript module.exports = { + 'board' : { + 'text' : { + 'nextUp' : 'Next Up', + 'statusAvailable' : 'Open', + 'statusBusy' : 'Busy', + 'statusError' : 'Error' + } + }, + + 'navbar' : { 'title' : 'Conference Room Availability', + }, + + 'roomFilter' : { 'filterTitle' : 'Locations', 'filterAllTitle' : 'All Conference Rooms', - 'roomsToSkip' : [ - 'ROOM_EMAIL@DOMAIN.COM' - ], - 'socketEndpoint' : 'http://localhost:8080' + }, + + 'socket' : { + 'endpoint' : 'http://localhost:8080', + } }; ``` @@ -181,7 +197,7 @@ There are three main directories in the `ui-react/src/` folder: * To change the interval in which the web socket emits, edit the interval time in `config/controller.js`. By default, it is set to 1 minute. * To update styles, make sure you install grunt first with `npm install -g grunt-cli`. Then run `grunt` in the root directory to watch for SCSS changes. Use the `.scss` files located in the `/scss` folder. * All React components can be locally styled by adding a new `.css` file and importing it into the component itself if you'd prefer to do it that way. -* In `config/ews/rooms.js`, there is a block of code on lines 37-39 that may not be necessary but were added as a convenience. Feel free to use it, comment it out, or remove it completely. It was designed for a use case where the email addresses (ex: jsmith@domain.com) do not match the corporate domain (ex: jsmith-enterprise). +* In `config/ews/rooms.js`, there is a block of code that may not be necessary but were added as a convenience. Feel free to use it, comment it out, or remove it completely. It was designed for a use case where the email addresses (ex: jsmith@domain.com) do not match the corporate domain (ex: jsmith-enterprise). ```javascript // if the email domain != your corporate domain, // replace email domain with domain from auth config