Remove algolia from chat channel memberships (#6323)

This commit is contained in:
Molly Struve 2020-02-27 09:59:12 -05:00 committed by GitHub
parent c8b56d1788
commit 9863d70b57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 11 additions and 45 deletions

View file

@ -26,7 +26,6 @@ class ChatChannelMembershipsController < ApplicationController
authorize @chat_channel_membership
if permitted_params[:user_action] == "accept"
@chat_channel_membership.update(status: "active")
@chat_channel_membership.index!
else
@chat_channel_membership.update(status: "rejected")
end
@ -42,7 +41,6 @@ class ChatChannelMembershipsController < ApplicationController
chat_channel_memberships.where(user_id: current_user.id).first
authorize @chat_channel_membership
@chat_channel_membership.update(status: "left_channel")
@chat_channel_membership.remove_from_index!
@chat_channels_memberships = []
render json: { result: "left channel" }, status: :created
end

View file

@ -38,7 +38,6 @@ class ChatChannelsController < ApplicationController
membership = @chat_channel.chat_channel_memberships.where(user_id: current_user.id).first
membership.update(last_opened_at: 1.second.from_now, has_unopened_messages: false)
send_open_notification
membership.index!
render json: { status: "success", channel: params[:id] }, status: :ok
end
@ -95,7 +94,7 @@ class ChatChannelsController < ApplicationController
authorize chat_channel
chat_channel.status = "blocked"
chat_channel.save
chat_channel.chat_channel_memberships.map(&:remove_from_index!)
chat_channel.chat_channel_memberships.map(&:index_to_elasticsearch)
render json: { status: "success", message: "chat channel blocked" }, status: :ok
end
@ -142,26 +141,15 @@ class ChatChannelsController < ApplicationController
end
def render_channels_html
return unless current_user
return unless current_user && params[:slug]
if params[:slug]
slug = if params[:slug]&.start_with?("@")
[current_user.username, params[:slug].delete("@")].sort.join("/")
else
params[:slug]
end
@active_channel = ChatChannel.find_by(slug: slug)
@active_channel.current_user = current_user if @active_channel
end
generate_algolia_search_key
end
def generate_algolia_search_key
current_user_id = current_user.id
params = { filters: "viewable_by:#{current_user_id} AND status: active" }
@secured_algolia_key = Algolia.generate_secured_api_key(
ApplicationConfig["ALGOLIASEARCH_SEARCH_ONLY_KEY"], params
)
slug = if params[:slug]&.start_with?("@")
[current_user.username, params[:slug].delete("@")].sort.join("/")
else
params[:slug]
end
@active_channel = ChatChannel.find_by(slug: slug)
@active_channel.current_user = current_user if @active_channel
end
def generate_github_token

View file

@ -77,7 +77,6 @@ class ChatChannel < ApplicationRecord
status: "active",
)
channel.add_users(users)
channel.chat_channel_memberships.map(&:index!)
end
channel
end

View file

@ -1,6 +1,4 @@
class ChatChannelMembership < ApplicationRecord
include AlgoliaSearch
include Searchable
SEARCH_SERIALIZER = Search::ChatChannelMembershipSerializer
SEARCH_CLASS = Search::ChatChannelMembership
@ -17,15 +15,6 @@ class ChatChannelMembership < ApplicationRecord
after_commit :index_to_elasticsearch, on: %i[create update]
after_commit :remove_from_elasticsearch, on: [:destroy]
algoliasearch index_name: "SecuredChatChannelMembership_#{Rails.env}", auto_index: false do
attribute :id, :status, :viewable_by, :chat_channel_id, :last_opened_at,
:channel_text, :channel_last_message_at, :channel_status, :channel_type, :channel_username,
:channel_name, :channel_image, :channel_modified_slug, :channel_messages_count
searchableAttributes %i[channel_text]
attributesForFaceting ["filterOnly(viewable_by)", "filterOnly(status)", "filterOnly(channel_status)", "filterOnly(channel_type)"]
ranking ["desc(channel_last_message_at)"]
end
delegate :channel_type, to: :chat_channel
def channel_last_message_at

View file

@ -27,7 +27,7 @@ class Message < ApplicationRecord
def update_chat_channel_last_message_at
chat_channel.touch(:last_message_at)
chat_channel.chat_channel_memberships.reindex!
chat_channel.chat_channel_memberships.each(&:index_to_elasticsearch)
end
def update_all_has_unopened_messages_statuses

View file

@ -20,7 +20,6 @@ module UserBlocks
chat_channel.update(status: "blocked")
chat_channel.chat_channel_memberships.includes([:user]).each do |membership|
membership.update(status: "left_channel")
membership.remove_from_index!
end
end
@ -31,7 +30,6 @@ module UserBlocks
chat_channel.update(status: "active")
chat_channel.chat_channel_memberships.includes([:user]).each do |membership|
membership.update(status: "active")
membership.index!
end
end
end

View file

@ -13,10 +13,7 @@ module Users
end
def self.cleanup_memberships(chat_channel_memberships)
chat_channel_memberships.each do |ccm|
ccm.remove_from_index!
ccm.destroy!
end
chat_channel_memberships.each(&:destroy!)
end
private_class_method :cleanup_memberships
end

View file

@ -12,9 +12,6 @@
id="chat"
class="live-chat"
data-pusher-key="<%= ApplicationConfig["PUSHER_KEY"] %>"
data-algolia-id="<%= ApplicationConfig["ALGOLIASEARCH_APPLICATION_ID"] %>"
data-algolia-key="<%= @secured_algolia_key %>"
data-algolia-index="<%= "SecuredChatChannelMembership_#{Rails.env}" %>"
data-github-token="<%= @github_token %>"
data-chat-channels="<%= [] %>"
data-chat-options="<%= { showChannelsList: true, showTimestamp: true, activeChannelId: @active_channel&.id, currentUserId: current_user.id }.to_json %>">