Setup Circle CI, add brakeman config (#13)

* Add circle ci config

* Change config to fix tests

* Update config

* Fix eslint command, add brakeman
This commit is contained in:
Pranav Raj S
2019-08-21 12:59:56 +05:30
committed by GitHub
parent 6e4fec2b55
commit 2c144d5ad3
39 changed files with 847 additions and 616 deletions

View File

@@ -24,44 +24,51 @@ const getters = {
const actions = {
fetchAgents({ commit }) {
commit(types.default.SET_AGENT_FETCHING_STATUS, true);
Account.getAgents().then((response) => {
commit(types.default.SET_AGENT_FETCHING_STATUS, false);
commit(types.default.SET_AGENTS, response);
}).catch();
Account.getAgents()
.then(response => {
commit(types.default.SET_AGENT_FETCHING_STATUS, false);
commit(types.default.SET_AGENTS, response);
})
.catch();
},
addAgent({ commit }, agentInfo) {
return new Promise((resolve, reject) => {
Account.addAgent(agentInfo).then((response) => {
commit(types.default.ADD_AGENT, response);
resolve();
}).catch((response) => {
reject(response);
});
Account.addAgent(agentInfo)
.then(response => {
commit(types.default.ADD_AGENT, response);
resolve();
})
.catch(response => {
reject(response);
});
});
},
editAgent({ commit }, agentInfo) {
return new Promise((resolve, reject) => {
Account.editAgent(agentInfo).then((response) => {
commit(types.default.EDIT_AGENT, response, agentInfo.id);
resolve();
}).catch((response) => {
reject(response);
});
Account.editAgent(agentInfo)
.then(response => {
commit(types.default.EDIT_AGENT, response, agentInfo.id);
resolve();
})
.catch(response => {
reject(response);
});
});
},
deleteAgent({ commit }, agentId) {
return new Promise((resolve, reject) => {
Account.deleteAgent(agentId).then((response) => {
if (response.status === 200) {
commit(types.default.DELETE_AGENT, agentId);
}
resolve();
}).catch((response) => {
reject(response);
});
Account.deleteAgent(agentId)
.then(response => {
if (response.status === 200) {
commit(types.default.DELETE_AGENT, agentId);
}
resolve();
})
.catch(response => {
reject(response);
});
});
},
};
const mutations = {

View File

@@ -37,12 +37,16 @@ const getters = {
},
getSubscription(_state) {
return _state.currentUser.subscription === undefined ? null : _state.currentUser.subscription;
return _state.currentUser.subscription === undefined
? null
: _state.currentUser.subscription;
},
getTrialLeft(_state) {
const createdAt = _state.currentUser.subscription === undefined ?
moment() : _state.currentUser.subscription.expiry * 1000;
const createdAt =
_state.currentUser.subscription === undefined
? moment()
: _state.currentUser.subscription.expiry * 1000;
const daysLeft = moment(createdAt).diff(moment(), 'days');
return daysLeft < 0 ? 0 : daysLeft;
},
@@ -52,17 +56,18 @@ const getters = {
const actions = {
login({ commit }, credentials) {
return new Promise((resolve, reject) => {
authAPI.login(credentials)
.then(() => {
commit(types.default.SET_CURRENT_USER);
window.axios = createAxios(axios);
window.pusher = vuePusher.init(Vue);
router.replace({ name: 'home' });
resolve();
})
.catch((error) => {
reject(error);
});
authAPI
.login(credentials)
.then(() => {
commit(types.default.SET_CURRENT_USER);
window.axios = createAxios(axios);
window.pusher = vuePusher.init(Vue);
router.replace({ name: 'home' });
resolve();
})
.catch(error => {
reject(error);
});
});
},
validityCheck(context) {

View File

@@ -23,13 +23,21 @@ const actions = {
fetchSubscription({ commit }) {
commit(types.default.TOGGLE_SUBSCRIPTION_LOADING, true);
Billing.getSubscription()
.then((billingDetails) => {
.then(billingDetails => {
commit(types.default.SET_SUBSCRIPTION, billingDetails.data);
commit(types.default.TOGGLE_SUBSCRIPTION_LOADING, false, billingDetails.status);
commit(
types.default.TOGGLE_SUBSCRIPTION_LOADING,
false,
billingDetails.status
);
})
.catch((error) => {
.catch(error => {
const { response } = error;
commit(types.default.TOGGLE_SUBSCRIPTION_LOADING, false, response.status);
commit(
types.default.TOGGLE_SUBSCRIPTION_LOADING,
false,
response.status
);
});
},
};

View File

@@ -21,51 +21,60 @@ const getters = {
const actions = {
fetchCannedResponse({ commit }) {
commit(types.default.SET_CANNED_FETCHING_STATUS, true);
CannedApi.getAllCannedResponses().then((response) => {
commit(types.default.SET_CANNED_FETCHING_STATUS, false);
commit(types.default.SET_CANNED, response);
}).catch();
CannedApi.getAllCannedResponses()
.then(response => {
commit(types.default.SET_CANNED_FETCHING_STATUS, false);
commit(types.default.SET_CANNED, response);
})
.catch();
},
searchCannedResponse({ commit }, { searchKey }) {
commit(types.default.SET_CANNED_FETCHING_STATUS, true);
CannedApi.searchCannedResponse({ searchKey }).then((response) => {
commit(types.default.SET_CANNED_FETCHING_STATUS, false);
commit(types.default.SET_CANNED, response);
}).catch();
CannedApi.searchCannedResponse({ searchKey })
.then(response => {
commit(types.default.SET_CANNED_FETCHING_STATUS, false);
commit(types.default.SET_CANNED, response);
})
.catch();
},
addCannedResponse({ commit }, cannedObj) {
return new Promise((resolve, reject) => {
CannedApi.addCannedResponse(cannedObj).then((response) => {
commit(types.default.ADD_CANNED, response);
resolve();
}).catch((response) => {
reject(response);
});
CannedApi.addCannedResponse(cannedObj)
.then(response => {
commit(types.default.ADD_CANNED, response);
resolve();
})
.catch(response => {
reject(response);
});
});
},
editCannedResponse({ commit }, cannedObj) {
return new Promise((resolve, reject) => {
CannedApi.editCannedResponse(cannedObj).then((response) => {
commit(types.default.EDIT_CANNED, response, cannedObj.id);
resolve();
}).catch((response) => {
reject(response);
});
CannedApi.editCannedResponse(cannedObj)
.then(response => {
commit(types.default.EDIT_CANNED, response, cannedObj.id);
resolve();
})
.catch(response => {
reject(response);
});
});
},
deleteCannedResponse({ commit }, responseId) {
return new Promise((resolve, reject) => {
CannedApi.deleteCannedResponse(responseId.id).then((response) => {
if (response.status === 200) {
commit(types.default.DELETE_CANNED, responseId);
}
resolve();
}).catch((response) => {
reject(response);
});
CannedApi.deleteCannedResponse(responseId.id)
.then(response => {
if (response.status === 200) {
commit(types.default.DELETE_CANNED, responseId);
}
resolve();
})
.catch(response => {
reject(response);
});
});
},
};
const mutations = {
@@ -96,7 +105,9 @@ const mutations = {
// Delete CannedResponse
[types.default.DELETE_CANNED](_state, { id }) {
_state.cannedResponse = _state.cannedResponse.filter(agent => agent.id !== id);
_state.cannedResponse = _state.cannedResponse.filter(
agent => agent.id !== id
);
},
};

View File

@@ -3,13 +3,10 @@
// const chatType = 'all';
// initial state
const state = {
};
const state = {};
// actions
const actions = {
};
const actions = {};
export default {
state,

View File

@@ -41,32 +41,42 @@ const getters = {
getMineChats(_state) {
const currentUserID = authAPI.getCurrentUser().id;
return _state.allConversations.filter(chat =>
(chat.meta.assignee === null ?
false : chat.status === _state.chatStatusFilter && chat.meta.assignee.id === currentUserID)
chat.meta.assignee === null
? false
: chat.status === _state.chatStatusFilter &&
chat.meta.assignee.id === currentUserID
);
},
getUnAssignedChats(_state) {
return _state.allConversations.filter(chat =>
chat.meta.assignee === null && chat.status === _state.chatStatusFilter
return _state.allConversations.filter(
chat =>
chat.meta.assignee === null && chat.status === _state.chatStatusFilter
);
},
getAllStatusChats(_state) {
return _state.allConversations.filter(chat =>
chat.status === _state.chatStatusFilter
return _state.allConversations.filter(
chat => chat.status === _state.chatStatusFilter
);
},
getChatListLoadingStatus(_state) {
return _state.listLoadingStatus;
},
getAllMessagesLoaded(_state) {
const [chat] = _state.allConversations.filter(c => c.id === _state.selectedChat.id);
return chat.allMessagesLoaded === undefined ? false : chat.allMessagesLoaded;
const [chat] = _state.allConversations.filter(
c => c.id === _state.selectedChat.id
);
return chat.allMessagesLoaded === undefined
? false
: chat.allMessagesLoaded;
},
getUnreadCount(_state) {
const [chat] = _state.allConversations.filter(c => c.id === _state.selectedChat.id);
return chat.messages.filter(chatMessage =>
chatMessage.created_at * 1000 > chat.agent_last_seen_at * 1000 &&
(chatMessage.message_type === 0 && chatMessage.private !== true)
const [chat] = _state.allConversations.filter(
c => c.id === _state.selectedChat.id
);
return chat.messages.filter(
chatMessage =>
chatMessage.created_at * 1000 > chat.agent_last_seen_at * 1000 &&
(chatMessage.message_type === 0 && chatMessage.private !== true)
).length;
},
getChatStatusFilter(_state) {
@@ -79,12 +89,15 @@ const getters = {
// actions
const actions = {
fetchAllConversations({ commit }, fetchParams) {
commit(types.default.SET_LIST_LOADING_STATUS);
ChatList.fetchAllConversations(fetchParams, (response) => {
commit(types.default.SET_ALL_CONVERSATION, { chats: response.data.data.payload });
commit(types.default.SET_CONV_TAB_META, { meta: response.data.data.meta });
ChatList.fetchAllConversations(fetchParams, response => {
commit(types.default.SET_ALL_CONVERSATION, {
chats: response.data.data.payload,
});
commit(types.default.SET_CONV_TAB_META, {
meta: response.data.data.meta,
});
commit(types.default.CLEAR_LIST_LOADING_STATUS);
});
},
@@ -98,25 +111,28 @@ const actions = {
},
fetchPreviousMessages({ commit }, data) {
const donePromise = new Promise((resolve) => {
messageApi.fetchPreviousMessages(data).then((response) => {
commit(types.default.SET_PREVIOUS_CONVERSATIONS, {
id: data.id,
data: response.data.payload,
const donePromise = new Promise(resolve => {
messageApi
.fetchPreviousMessages(data)
.then(response => {
commit(types.default.SET_PREVIOUS_CONVERSATIONS, {
id: data.id,
data: response.data.payload,
});
if (response.data.payload.length < 20) {
commit(types.default.SET_ALL_MESSAGES_LOADED);
}
resolve();
})
.catch(error => {
console.log(error);
});
if (response.data.payload.length < 20) {
commit(types.default.SET_ALL_MESSAGES_LOADED);
}
resolve();
}).catch((error) => {
console.log(error);
});
});
return donePromise;
},
setActiveChat(store, data) {
const commit = store.commit;
const { commit } = store;
const localDispatch = store.dispatch;
let donePromise = null;
@@ -124,19 +140,21 @@ const actions = {
commit(types.default.CLEAR_ALL_MESSAGES_LOADED);
if (data.dataFetched === undefined) {
donePromise = new Promise((resolve) => {
donePromise = new Promise(resolve => {
localDispatch('fetchPreviousMessages', {
id: data.id,
before: data.messages[0].id,
}).then(() => {
Vue.set(data, 'dataFetched', true);
resolve();
}).catch((error) => {
console.log(error);
});
})
.then(() => {
Vue.set(data, 'dataFetched', true);
resolve();
})
.catch(error => {
console.log(error);
});
});
} else {
donePromise = new Promise((resolve) => {
donePromise = new Promise(resolve => {
commit(types.default.SET_CHAT_META, { id: data.id });
resolve();
});
@@ -145,8 +163,8 @@ const actions = {
},
assignAgent({ commit }, data) {
return new Promise((resolve) => {
ConversationApi.assignAgent(data).then((response) => {
return new Promise(resolve => {
ConversationApi.assignAgent(data).then(response => {
commit(types.default.ASSIGN_AGENT, response.data);
resolve(response.data);
});
@@ -154,9 +172,12 @@ const actions = {
},
toggleStatus({ commit }, data) {
return new Promise((resolve) => {
ConversationApi.toggleStatus(data).then((response) => {
commit(types.default.RESOLVE_CONVERSATION, response.data.payload.current_status);
return new Promise(resolve => {
ConversationApi.toggleStatus(data).then(response => {
commit(
types.default.RESOLVE_CONVERSATION,
response.data.payload.current_status
);
resolve(response.data);
});
});
@@ -167,20 +188,26 @@ const actions = {
// },
sendMessage({ commit }, data) {
return new Promise((resolve) => {
messageApi.sendMessage(data).then((response) => {
commit(types.default.SEND_MESSAGE, response);
resolve();
}).catch();
return new Promise(resolve => {
messageApi
.sendMessage(data)
.then(response => {
commit(types.default.SEND_MESSAGE, response);
resolve();
})
.catch();
});
},
addPrivateNote({ commit }, data) {
return new Promise((resolve) => {
messageApi.addPrivateNote(data).then((response) => {
commit(types.default.SEND_MESSAGE, response);
resolve();
}).catch();
return new Promise(resolve => {
messageApi
.addPrivateNote(data)
.then(response => {
commit(types.default.SEND_MESSAGE, response);
resolve();
})
.catch();
});
},
@@ -192,22 +219,25 @@ const actions = {
commit(types.default.ADD_CONVERSATION, conversation);
},
toggleTyping({ commit }, data) {
return new Promise((resolve) => {
ConversationApi.fbTyping(data).then(() => {
commit(types.default.FB_TYPING, data);
resolve();
}).catch();
return new Promise(resolve => {
ConversationApi.fbTyping(data)
.then(() => {
commit(types.default.FB_TYPING, data);
resolve();
})
.catch();
});
},
markSeen({ commit }, data) {
return new Promise((resolve) => {
ConversationApi.markSeen(data).then((response) => {
commit(types.default.MARK_SEEN, response);
resolve();
}).catch();
return new Promise(resolve => {
ConversationApi.markSeen(data)
.then(response => {
commit(types.default.MARK_SEEN, response);
resolve();
})
.catch();
});
},
@@ -215,10 +245,12 @@ const actions = {
setTimeout(() => {
commit(types.default.MARK_MESSAGE_READ, data);
}, 4000);
return new Promise((resolve) => {
ConversationApi.markMessageRead(data).then(() => {
resolve();
}).catch();
return new Promise(resolve => {
ConversationApi.markMessageRead(data)
.then(() => {
resolve();
})
.catch();
});
},
@@ -237,8 +269,6 @@ const actions = {
// mutations
const mutations = {
[types.default.SET_ALL_CONVERSATION](_state, data) {
if (data) {
_state.allConversations.push(...data.chats);
@@ -258,12 +288,16 @@ const mutations = {
},
[types.default.SET_ALL_MESSAGES_LOADED](_state) {
const [chat] = _state.allConversations.filter(c => c.id === _state.selectedChat.id);
const [chat] = _state.allConversations.filter(
c => c.id === _state.selectedChat.id
);
Vue.set(chat, 'allMessagesLoaded', true);
},
[types.default.CLEAR_ALL_MESSAGES_LOADED](_state) {
const [chat] = _state.allConversations.filter(c => c.id === _state.selectedChat.id);
const [chat] = _state.allConversations.filter(
c => c.id === _state.selectedChat.id
);
Vue.set(chat, 'allMessagesLoaded', false);
},
@@ -311,7 +345,9 @@ const mutations = {
},
[types.default.ASSIGN_AGENT](_state, assignee) {
const [chat] = _state.allConversations.filter(c => c.id === _state.selectedChat.id);
const [chat] = _state.allConversations.filter(
c => c.id === _state.selectedChat.id
);
chat.meta.assignee = assignee;
if (assignee === null) {
Object.assign(_state.selectedChat.meta.assignee, assignee);
@@ -319,13 +355,17 @@ const mutations = {
},
[types.default.RESOLVE_CONVERSATION](_state, status) {
const [chat] = _state.allConversations.filter(c => c.id === _state.selectedChat.id);
const [chat] = _state.allConversations.filter(
c => c.id === _state.selectedChat.id
);
chat.status = status;
_state.selectedChat.status = status;
},
[types.default.SEND_MESSAGE](_state, response) {
const [chat] = _state.allConversations.filter(c => c.id === _state.selectedChat.id);
const [chat] = _state.allConversations.filter(
c => c.id === _state.selectedChat.id
);
const previousMessageIds = chat.messages.map(m => m.id);
if (!previousMessageIds.includes(response.data.id)) {
chat.messages.push(response.data);
@@ -333,7 +373,9 @@ const mutations = {
},
[types.default.ADD_MESSAGE](_state, message) {
const [chat] = _state.allConversations.filter(c => c.id === message.conversation_id);
const [chat] = _state.allConversations.filter(
c => c.id === message.conversation_id
);
if (!chat) return;
const previousMessageIds = chat.messages.map(m => m.id);
if (!previousMessageIds.includes(message.id)) {

View File

@@ -35,24 +35,30 @@ const getters = {
const actions = {
fetchAccountReport({ commit }, reportObj) {
commit(types.default.TOGGLE_ACCOUNT_REPORT_LOADING, true);
Report.getAccountReports(reportObj.metric, reportObj.from, reportObj.to)
.then((accountReport) => {
let { data } = accountReport;
data = data.filter(el => moment() > moment.unix(el.timestamp));
if (reportObj.metric === 'avg_first_response_time' || reportObj.metric === 'avg_resolution_time') {
data = data.map((element) => {
/* eslint-disable operator-assignment*/
element.value = (element.value / 3600).toFixed(2);
return element;
});
}
commit(types.default.SET_ACCOUNT_REPORTS, data);
commit(types.default.TOGGLE_ACCOUNT_REPORT_LOADING, false);
});
Report.getAccountReports(
reportObj.metric,
reportObj.from,
reportObj.to
).then(accountReport => {
let { data } = accountReport;
data = data.filter(el => moment() > moment.unix(el.timestamp));
if (
reportObj.metric === 'avg_first_response_time' ||
reportObj.metric === 'avg_resolution_time'
) {
data = data.map(element => {
/* eslint-disable operator-assignment */
element.value = (element.value / 3600).toFixed(2);
return element;
});
}
commit(types.default.SET_ACCOUNT_REPORTS, data);
commit(types.default.TOGGLE_ACCOUNT_REPORT_LOADING, false);
});
},
fetchAccountSummary({ commit }, reportObj) {
Report.getAccountSummary(1, reportObj.from, reportObj.to)
.then((accountSummary) => {
.then(accountSummary => {
commit(types.default.SET_ACCOUNT_SUMMARY, accountSummary.data);
})
.catch(() => {
@@ -73,13 +79,17 @@ const mutations = {
// Average First Response Time
let avgFirstResTimeInHr = 0;
if (summaryData.avg_first_response_time) {
avgFirstResTimeInHr = (summaryData.avg_first_response_time / 3600).toFixed(2);
avgFirstResTimeInHr = (
summaryData.avg_first_response_time / 3600
).toFixed(2);
avgFirstResTimeInHr = `${avgFirstResTimeInHr} Hr`;
}
// Average Resolution Time
let avgResolutionTimeInHr = 0;
if (summaryData.avg_resolution_time) {
avgResolutionTimeInHr = (summaryData.avg_resolution_time / 3600).toFixed(2);
avgResolutionTimeInHr = (summaryData.avg_resolution_time / 3600).toFixed(
2
);
avgResolutionTimeInHr = `${avgResolutionTimeInHr} Hr`;
}
_state.accountSummary.avg_first_response_time = avgFirstResTimeInHr;

View File

@@ -27,28 +27,32 @@ const getters = {
const actions = {
// Fetch Labels
fetchLabels({ commit }) {
Account.getLabels().then((response) => {
commit(types.default.SET_LABELS, response.data);
}).catch();
Account.getLabels()
.then(response => {
commit(types.default.SET_LABELS, response.data);
})
.catch();
},
// Fetch Inboxes
fetchInboxes({ commit }) {
commit(types.default.INBOXES_LOADING, true);
return new Promise((resolve, reject) => {
Account.getInboxes().then((response) => {
commit(types.default.INBOXES_LOADING, false);
commit(types.default.SET_INBOXES, response.data);
resolve();
}).catch((error) => {
commit(types.default.INBOXES_LOADING, false);
reject(error);
});
Account.getInboxes()
.then(response => {
commit(types.default.INBOXES_LOADING, false);
commit(types.default.SET_INBOXES, response.data);
resolve();
})
.catch(error => {
commit(types.default.INBOXES_LOADING, false);
reject(error);
});
});
},
deleteInbox({ commit }, id) {
return new Promise((resolve, reject) => {
Account.deleteInbox(id)
.then((response) => {
.then(response => {
if (response.status === 200) {
commit(types.default.DELETE_INBOX, id);
resolve();
@@ -56,48 +60,50 @@ const actions = {
reject();
}
})
.catch((error) => {
.catch(error => {
reject(error);
});
});
},
addInboxItem({ commit }, { channel, params }) {
const donePromise = new Promise((resolve) => {
ChannelApi.createChannel(channel, params).then((response) => {
commit(types.default.SET_INBOX_ITEM, response);
resolve(response);
}).catch((error) => {
console.log(error);
});
const donePromise = new Promise(resolve => {
ChannelApi.createChannel(channel, params)
.then(response => {
commit(types.default.SET_INBOX_ITEM, response);
resolve(response);
})
.catch(error => {
console.log(error);
});
});
return donePromise;
},
listInboxAgents({ commit }, { inboxId }) {
listInboxAgents(_, { inboxId }) {
return new Promise((resolve, reject) => {
Account.listInboxAgents(inboxId)
.then((response) => {
.then(response => {
if (response.status === 200) {
resolve(response.data);
} else {
reject();
}
})
.catch((error) => {
.catch(error => {
reject(error);
});
});
},
updateInboxAgents({ commit }, { inboxId, agentList }) {
updateInboxAgents(_, { inboxId, agentList }) {
return new Promise((resolve, reject) => {
Account.updateInboxAgents(inboxId, agentList)
.then((response) => {
.then(response => {
if (response.status === 200) {
resolve(response.data);
} else {
reject();
}
})
.catch((error) => {
.catch(error => {
reject(error);
});
});
@@ -105,7 +111,6 @@ const actions = {
};
const mutations = {
// Set Labels
[types.default.SET_LABELS](_state, data) {
let payload = data.data.payload.labels;
@@ -116,7 +121,7 @@ const mutations = {
// Identify menuItem to update
// May have more than one object to update
// Iterate it accordingly. Updating commmon sidebar now.
const menuItems = _state.menuGroup.common.menuItems;
const { menuItems } = _state.menuGroup.common;
// Update children for key `label`
menuItems.labels.children = payload;
},
@@ -126,7 +131,7 @@ const mutations = {
},
// Set Inboxes
[types.default.SET_INBOXES](_state, data) {
let payload = data.data.payload;
let { payload } = data.data;
payload = payload.map(item => ({
channel_id: item.id,
label: item.name,
@@ -138,13 +143,13 @@ const mutations = {
// Identify menuItem to update
// May have more than one object to update
// Iterate it accordingly. Updating commmon sidebar now.
const menuItems = _state.menuGroup.common.menuItems;
const { menuItems } = _state.menuGroup.common;
// Update children for key `inbox`
menuItems.inbox.children = payload;
},
[types.default.SET_INBOX_ITEM](_state, { data }) {
const menuItems = _state.menuGroup.common.menuItems;
const { menuItems } = _state.menuGroup.common;
// Update children for key `inbox`
menuItems.inbox.children.push({
channel_id: data.id,
@@ -157,13 +162,11 @@ const mutations = {
},
[types.default.DELETE_INBOX](_state, id) {
const menuItems = _state.menuGroup.common.menuItems;
const { menuItems } = _state.menuGroup.common;
let inboxList = menuItems.inbox.children;
inboxList = inboxList.filter(inbox => inbox.channel_id !== id);
menuItems.inbox.children = inboxList;
},
};
export default {