docbrown/app/controllers/search_controller.rb
Sarthak Sharma 90d60bf73f
[deploy] 🚀 Feature: Ability to search discoverable channels and send request to join (#7385)
* Feature 🚀 : Ability to delete messages in chat channels

- Sending message ID to frontend
- Deleting Message
- Use pusher to delete message realtime

* Minor Bug 🐞: Show message action only for current user

- User can delete or edit their own messages

* Test cases added

* Bug 🐞: Update message id for receiver

Message id was not sent to receiver by pusher

* Refactoring🛠: Message controller refactoring

* Test Cases📝 : Specs for Delete message added

* Feature 🚀 : Ability to edit messages

* Test Cases📝 : Specs for Edit message added

* added new column discoverable for public channel and changes in elasticsearch

* fix corrections

* changes in serializer file, added channel_discoverable

* added checkbox with discoverable policy

* changes in code for discoverable channels

* accept and reject member invitation by mod

* add joining request to closed groups

* fixed merge error

* changes in joining member to closed groups

* join to closed group

* changes in message action of joining

* changes in chat upopened json

* 🚀Feature : Ability to search Global Channels

* touch updated_at in after commit update

* 🚀Feature : Ability to send request to discoverable channel

* 🚀Feature : Ability to send request to discoverable channel

* created new route for joining closed channel

* 🚀 Success handle on joining request sent

* removed redundant code

* join_channel improvement, removed authorization for join channel

* list of joining requests

* added joining_request status channels on search list

* changes in mailer and query builder optimized

* 🛠 Adding filter for new Query

* added rspec for add membership method in controller

* rspec for sending join channel request

* invite join request channel list rspec

* test case for query builder discoverable

* viewable and discoverable channel list

* refactored logic for search channels

* 🚀 Check if Request already sent

* 🛠 Optimizing code and making channelButton Component

* 🛠 Optimizing codefor SVG problem

* 🛠 Optimized action.js

* changes in search controller query

* hot fix

* removed unwanted code

* 🛠  Fix the Channel Name problem

* 🛠  Optimizing code further for CodeClimate

* added new column discoverable for public channel and changes in elasticsearch

* fix corrections

* changes in serializer file, added channel_discoverable

* added checkbox with discoverable policy

* changes in code for discoverable channels

* accept and reject member invitation by mod

* add joining request to closed groups

* fixed merge error

* changes in joining member to closed groups

* join to closed group

* changes in message action of joining

* changes in chat upopened json

* touch updated_at in after commit update

* 🚀Feature : Ability to search Global Channels

* 🚀Feature : Ability to send request to discoverable channel

* 🚀Feature : Ability to send request to discoverable channel

* created new route for joining closed channel

* 🚀 Success handle on joining request sent

* removed redundant code

* join_channel improvement, removed authorization for join channel

* list of joining requests

* added joining_request status channels on search list

* changes in mailer and query builder optimized

* added rspec for add membership method in controller

* rspec for sending join channel request

* invite join request channel list rspec

* 🛠 Adding filter for new Query

* test case for query builder discoverable

* viewable and discoverable channel list

* refactored logic for search channels

* 🚀 Check if Request already sent

* 🛠 Optimizing code and making channelButton Component

* 🛠 Optimizing codefor SVG problem

* 🛠 Optimized action.js

* changes in search controller query

* hot fix

* 🛠  Fix the Channel Name problem

* 🛠  Fixing merge problem

* 🛠  Optimizing code further for CodeClimate

* updated UI for membership edit

* fixed test casses and fixed UI for chat_channel_edit

* 🛠napshots added

* test cases fixed

* 🛠 Test cases added for new component

* channel settings accesible only by mod

* 🛠 More Test cases added

* 🛠 Svg code optimized

* 🛠 Svg code optimized in videocontent

* optimized code for search query

* fix test case for query builder

* changes in joining closed channel logic

* refactored join channel

* redirect to edit channel after joining request

* changes in test case for redirect

* optimized code

* 🛠 Eslint bugs fixed

* test case fixed

* optimization

* olving channel repetition problem

* optimization of code for query builder

* changes in query builder

* test cases fixed

* 🛠 Handling reduntant data on frontend

* 🛠  Don't show data if no filter query

* 🛠 Optimized code for fixing bugs and code coverage

* 🛠  Optimizing code further for CodeClimate

Co-authored-by: Parasgr-code <paras.gaur@skynox.tech>
2020-05-11 09:29:15 -04:00

155 lines
3.6 KiB
Ruby

class SearchController < ApplicationController
before_action :authenticate_user!, only: %i[tags chat_channels reactions]
before_action :format_integer_params
before_action :sanitize_params, only: %i[classified_listings reactions feed_content]
CLASSIFIED_LISTINGS_PARAMS = [
:category,
:classified_listing_search,
:page,
:per_page,
:tag_boolean_mode,
{
tags: []
},
].freeze
REACTION_PARAMS = [
:page,
:per_page,
:category,
:search_fields,
:tag_boolean_mode,
{
tag_names: [],
status: []
},
].freeze
USER_PARAMS = %i[
search_fields
page
per_page
].freeze
FEED_PARAMS = [
:approved,
:class_name,
:organization_id,
:page,
:per_page,
:search_fields,
:sort_by,
:sort_direction,
:user_id,
{
tag_names: [],
published_at: [:gte]
},
].freeze
def tags
tag_docs = Search::Tag.search_documents("name:#{params[:name]}* AND supported:true")
render json: { result: tag_docs }
rescue Search::Errors::Transport::BadRequest
render json: { result: [] }
end
def chat_channels
search_user_id = chat_channel_params[:user_id].present? ? [current_user.id, SiteConfig.mascot_user_id] : [current_user.id]
ccm_docs = Search::ChatChannelMembership.search_documents(
params: chat_channel_params.merge(user_id: search_user_id).to_h,
)
render json: { result: ccm_docs }
end
def classified_listings
cl_docs = Search::ClassifiedListing.search_documents(
params: classified_listing_params.to_h,
)
render json: { result: cl_docs }
end
def users
render json: { result: user_search }
end
def feed_content
feed_docs = if params[:class_name].blank?
# If we are in the main feed and not filtering by type return
# all articles, podcast episodes, and users
feed_content_search.concat(user_search)
elsif params[:class_name] == "User"
# No need to check for articles or podcast episodes if we know we only want users
user_search
else
# if params[:class_name] == PodcastEpisode, Article, or Comment then skip user lookup
feed_content_search
end
render json: { result: feed_docs }
end
def reactions
result = Search::Reaction.search_documents(
params: reaction_params.merge(user_id: current_user.id).to_h,
)
render json: { result: result["reactions"], total: result["total"] }
end
private
def feed_content_search
Search::FeedContent.search_documents(params: feed_params.to_h)
end
def user_search
Search::User.search_documents(params: user_params.to_h)
end
def chat_channel_params
accessible = %i[
per_page
page
channel_text
channel_type
channel_status
status
user_id
]
params.permit(accessible)
end
def classified_listing_params
params.permit(CLASSIFIED_LISTINGS_PARAMS)
end
def user_params
params.permit(USER_PARAMS)
end
def feed_params
params.permit(FEED_PARAMS)
end
def reaction_params
params.permit(REACTION_PARAMS)
end
def format_integer_params
params[:page] = params[:page].to_i if params[:page].present?
params[:per_page] = params[:per_page].to_i if params[:per_page].present?
end
# Some Elasticsearches/QueryBuilders treat values such as empty Strings and
# nil differently. This is a helper method to remove any params that are
# blank before passing it to Elasticsearch.
def sanitize_params
params.delete_if { |_k, v| v.blank? }
end
end