diff --git a/Gemfile b/Gemfile index 902508044..70fd33c24 100644 --- a/Gemfile +++ b/Gemfile @@ -21,7 +21,7 @@ gem "bourbon", "~> 1.4" gem "buffer", github: "bufferapp/buffer-ruby" gem "carrierwave", "~> 1.2" gem "carrierwave-bombshelter", "~> 0.2" -gem "cloudinary", "~> 1.8" +gem "cloudinary", "~> 1.9" gem "counter_culture", "~> 1.9" gem "csv_shaper", "~> 1.3" gem "dalli", "~> 2.7" diff --git a/Gemfile.lock b/Gemfile.lock index 7707f9f1e..af8c30587 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -169,7 +169,7 @@ GEM chromedriver-helper (1.2.0) archive-zip (~> 0.10) nokogiri (~> 1.8) - cloudinary (1.8.3) + cloudinary (1.9.1) aws_cf_signer rest-client coderay (1.1.2) @@ -930,7 +930,7 @@ DEPENDENCIES carrierwave (~> 1.2) carrierwave-bombshelter (~> 0.2) chromedriver-helper (~> 1.2) - cloudinary (~> 1.8) + cloudinary (~> 1.9) counter_culture (~> 1.9) csv_shaper (~> 1.3) dalli (~> 2.7) diff --git a/app/controllers/admin/application_controller.rb b/app/controllers/admin/application_controller.rb index a1ccb06ce..aab00b3c7 100644 --- a/app/controllers/admin/application_controller.rb +++ b/app/controllers/admin/application_controller.rb @@ -20,7 +20,6 @@ module Admin request.origin.nil? || request.origin.gsub("https", "http") == request.base_url.gsub("https", "http") end - private def authorize_admin diff --git a/app/controllers/chat_channel_memberships_controller.rb b/app/controllers/chat_channel_memberships_controller.rb index 8f9665ca6..236a89420 100644 --- a/app/controllers/chat_channel_memberships_controller.rb +++ b/app/controllers/chat_channel_memberships_controller.rb @@ -1,26 +1,34 @@ class ChatChannelMembershipsController < ApplicationController + after_action :verify_authorized + def create - @chat_channel = ChatChannel.find(params[:chat_channel_id]) + @chat_channel = ChatChannel.find(permitted_params[:chat_channel_id]) authorize @chat_channel, :update? ChatChannelMembership.create( - user_id: params[:user_id], + user_id: permitted_params[:user_id], chat_channel_id: @chat_channel.id, status: "pending" ) + @chat_channel.index! end def update @chat_channel_membership = ChatChannelMembership.find(params[:id]) authorize @chat_channel_membership - if params[:user_action] == "accept" + if permitted_params[:user_action] == "accept" @chat_channel_membership.update(status: "active") else @chat_channel_membership.update(status: "rejected") end + @chat_channel_membership.chat_channel.index! @chat_channels_memberships = current_user. chat_channel_memberships.includes(:chat_channel). where(status: "pending"). order("chat_channel_memberships.updated_at DESC") render "chat_channels/index.json" end + + def permitted_params + params.require(:chat_channel_membership).permit(:user_id, :chat_channel_id, :user_action, :id) + end end \ No newline at end of file diff --git a/app/controllers/chat_channels_controller.rb b/app/controllers/chat_channels_controller.rb index 16e929f11..cae47719f 100644 --- a/app/controllers/chat_channels_controller.rb +++ b/app/controllers/chat_channels_controller.rb @@ -91,7 +91,7 @@ class ChatChannelsController < ApplicationController if current_user @chat_channels_memberships = current_user. chat_channel_memberships.includes(:chat_channel). - where(chat_channels: {channel_type: "direct"}, has_unopened_messages: true). + where(has_unopened_messages: true). order("chat_channel_memberships.updated_at DESC") else @chat_channels_memberships = [] diff --git a/app/javascript/chat/actions.js b/app/javascript/chat/actions.js index 19d6c9a04..aa663b89f 100644 --- a/app/javascript/chat/actions.js +++ b/app/javascript/chat/actions.js @@ -164,7 +164,9 @@ export function sendChannelInviteAction(id, action, successCb, failureCb) { 'Content-Type': 'application/json', }, body: JSON.stringify({ - user_action: action, + chat_channel_membership: { + user_action: action, + } }), credentials: 'same-origin', }) diff --git a/app/javascript/chat/channelDetails.jsx b/app/javascript/chat/channelDetails.jsx index e5a852532..4b7cb055e 100644 --- a/app/javascript/chat/channelDetails.jsx +++ b/app/javascript/chat/channelDetails.jsx @@ -2,7 +2,72 @@ import { h, Component } from 'preact'; +const algoliaId = document.querySelector("meta[name='algolia-public-id']").content +const algoliaKey = document.querySelector("meta[name='algolia-public-key']").content +const env = document.querySelector("meta[name='environment']").content +const client = algoliasearch(algoliaId, algoliaKey); +const index = client.initIndex('searchables_'+env); + export default class ChannelDetails extends Component { + constructor(props) { + super(props); + this.state = { + searchedUsers: [], + invitations: [] + } + } + + triggerUserSearch = e => { + const component = this; + const query = e.target.value; + const filters = { + hitsPerPage: 20, + attributesToRetrieve: [ + 'id', + 'title', + 'path' + ], + attributesToHighlight: [], + filters: 'class_name:User', + } + if (query.length > 0) { + index.search(query, filters) + .then(function(content) { + component.setState({searchedUsers:content.hits}) + }); + } else { + component.setState({searchedUsers:[]}) + } + } + + triggerInvite = e => { + const component = this; + const id = e.target.dataset.content; + console.log(e.target) + e.target.style.display = 'none' + fetch(`/chat_channel_memberships`, { + method: 'POST', + headers: { + Accept: 'application/json', + 'X-CSRF-Token': window.csrfToken, + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + chat_channel_membership: { + user_id: id, + chat_channel_id: component.props.channel.id, + } + }), + credentials: 'same-origin', + }) + .then(response => response) + .then(this.handleInvitationSuccess) + .catch(null); + } + + handleInvitationSuccess = response => { + console.log(response) + } render() { const channel = this.props.channel @@ -21,10 +86,30 @@ export default class ChannelDetails extends Component { if (users.length === 80) { subHeader =