This commit is contained in:
mgabdev
2020-12-15 19:31:30 -05:00
parent de0c977950
commit 75d52c841e
129 changed files with 2559 additions and 910 deletions

View File

@@ -0,0 +1,18 @@
# frozen_string_literal: true
module Admin
class ChatConversationsController < BaseController
before_action :set_account
PER_PAGE = 20
def index
authorize :account, :index?
@chatConversationAccounts = ChatConversationAccount.where(account: @account).page(params[:page]).per(PER_PAGE)
end
def set_account
@account = Account.find(params[:account_id])
end
end
end

View File

@@ -0,0 +1,18 @@
# frozen_string_literal: true
module Admin
class ChatMessagesController < BaseController
before_action :set_account
PER_PAGE = 100
def index
authorize :account, :index?
@followers = ChatMessage.where(from_account: @account).page(params[:page]).per(PER_PAGE)
end
def set_account
@account = Account.find(params[:account_id])
end
end
end

View File

@@ -5,6 +5,9 @@ module Admin
class DashboardController < BaseController
def index
@users_count = User.count
@statuses_count = Status.count
@pro_accounts_count = Account.where(is_pro: true).count
@donor_accounts_count = Account.where(is_donor: true).count
@registrations_week = Redis.current.get("activity:accounts:local:#{current_week}") || 0
@logins_week = Redis.current.pfcount("activity:logins:#{current_week}")
@interactions_week = Redis.current.get("activity:interactions:#{current_week}") || 0

View File

@@ -1,67 +1,75 @@
# frozen_string_literal: true
module Admin
class GroupsController < BaseController
before_action :set_group, except: [:index]
before_action :set_filter_params
def index
authorize :group, :index?
@groups = filtered_groups.page(params[:page])
end
def destroy
authorize @group, :destroy?
@group.destroy!
log_action :destroy, @group
flash[:notice] = I18n.t('admin.groups.destroyed_msg')
redirect_to admin_groups_path(page: params[:page], **@filter_params)
end
def enable_featured
authorize @group, :update?
@group.is_featured = true
@group.save!
log_action :update, @group
flash[:notice] = I18n.t('admin.groups.updated_msg')
redirect_to admin_groups_path(page: params[:page], **@filter_params)
end
def disable_featured
authorize @group, :update?
@group.is_featured = false
@group.save!
log_action :update, @group
flash[:notice] = I18n.t('admin.groups.updated_msg')
redirect_to admin_groups_path(page: params[:page], **@filter_params)
end
private
def set_group
@group = Group.find(params[:id])
end
def set_filter_params
@filter_params = filter_params.to_hash.symbolize_keys
end
def resource_params
params.require(:group).permit(:is_featured, :is_nsfw)
end
def filtered_groups
query = Group.order('is_featured DESC, member_count DESC')
if params[:title]
query = query.where("LOWER(title) LIKE LOWER(?)", "%#{params[:title]}%")
end
return query
end
def filter_params
params.permit(:sort,)
end
class GroupsController < BaseController
before_action :set_group, except: [:index]
before_action :set_filter_params
def index
authorize :group, :index?
@groups = filtered_groups.page(params[:page])
end
def show
authorize :group, :index?
end
def update
#
end
def destroy
authorize @group, :destroy?
@group.destroy!
log_action :destroy, @group
flash[:notice] = I18n.t('admin.groups.destroyed_msg')
redirect_to admin_groups_path(page: params[:page], **@filter_params)
end
def enable_featured
authorize @group, :update?
@group.is_featured = true
@group.save!
log_action :update, @group
flash[:notice] = I18n.t('admin.groups.updated_msg')
redirect_to admin_groups_path(page: params[:page], **@filter_params)
end
def disable_featured
authorize @group, :update?
@group.is_featured = false
@group.save!
log_action :update, @group
flash[:notice] = I18n.t('admin.groups.updated_msg')
redirect_to admin_groups_path(page: params[:page], **@filter_params)
end
private
def set_group
@group = Group.find(params[:id])
end
def set_filter_params
@filter_params = filter_params.to_hash.symbolize_keys
end
def resource_params
params.require(:group).permit(:is_featured, :is_nsfw)
end
def filtered_groups
query = Group.order('is_featured DESC, member_count DESC')
if params[:title]
query = query.where("LOWER(title) LIKE LOWER(?)", "%#{params[:title]}%")
end
return query
end
def filter_params
params.permit(:sort,)
end
end
end

View File

@@ -0,0 +1,18 @@
# frozen_string_literal: true
module Admin
class JoinedGroupsController < BaseController
before_action :set_account
PER_PAGE = 25
def index
authorize :account, :index?
@groups = @account.groups.page(params[:page]).per(PER_PAGE)
end
def set_account
@account = Account.find(params[:account_id])
end
end
end

View File

@@ -12,6 +12,7 @@ class Api::V1::Accounts::CredentialsController < Api::BaseController
def update
@account = current_account
# : todo : add link blocking check for bio
UpdateAccountService.new.call(@account, account_params, raise_error: true)
UserSettingsDecorator.new(current_user).update(user_settings_params) if user_settings_params
render json: @account, serializer: REST::CredentialAccountSerializer

View File

@@ -0,0 +1,44 @@
# frozen_string_literal: true
class Api::V1::AlbumsController < Api::BaseController
before_action :require_user!
before_action :set_albums, only: :index
before_action :set_album, only: [:show, :update, :destroy]
def index
render json: @albums, each_serializer: REST::AlbumSerializer
end
def create
@album = "" #current_account.custom_filters.create!(resource_params)
render json: @album, serializer: REST::AlbumSerializer
end
def show
render json: @album, serializer: REST::AlbumSerializer
end
def update
@album.update!(resource_params)
render json: @album, serializer: REST::AlbumSerializer
end
def destroy
@album.destroy!
render_empty_success
end
private
def set_albums
@albums = "" #current_account.custom_filters
end
def set_album
@album = "" # current_account.custom_filters.find(params[:id])
end
def resource_params
params.permit(:title, :description, :visibility)
end
end

View File

@@ -0,0 +1,44 @@
# frozen_string_literal: true
class Api::V1::BookmarkCollectionsController < Api::BaseController
before_action :require_user!
before_action :set_bookmark_collections, only: :index
before_action :set_bookmark_collection, only: [:show, :update, :destroy]
def index
render json: @bookmark_collections, each_serializer: REST::BookmarkCollectionSerializer
end
def create
@bookmark_collection = "" #current_account.custom_filters.create!(resource_params)
render json: @bookmark_collection, serializer: REST::BookmarkCollectionSerializer
end
def show
render json: @bookmark_collection, serializer: REST::BookmarkCollectionSerializer
end
def update
@bookmark_collection.update!(resource_params)
render json: @bookmark_collection, serializer: REST::BookmarkCollectionSerializer
end
def destroy
@bookmark_collection.destroy!
render_empty_success
end
private
def set_bookmark_collections
@bookmark_collections = "" #current_account.custom_filters
end
def set_bookmark_collection
@bookmark_collection = "" # current_account.custom_filters.find(params[:id])
end
def resource_params
params.permit(:title)
end
end

View File

@@ -35,6 +35,15 @@ class Api::V1::ChatConversationAccountsController < Api::BaseController
render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
end
def set_expiration_policy
if current_user.account.is_pro
#
render json: @chat_conversation_account, serializer: REST::ChatConversationAccountSerializer
else
render json: { error: 'You need to be a GabPRO member to access this' }, status: 422
end
end
private
def set_account

View File

@@ -6,7 +6,7 @@ class Api::V1::ChatConversationController < Api::BaseController
before_action :require_user!
before_action :set_account, only: :create
before_action :set_chat_conversation, only: [:show, :mark_chat_conversation_approved, :mark_chat_conversation_hidden, :mark_chat_conversation_unread]
before_action :set_chat_conversation, only: [:show, :mark_chat_conversation_approved, :mark_chat_conversation_hidden, :mark_chat_conversation_read]
def show
render json: {}, each_serializer: REST::ChatConversationAccountSerializer
@@ -23,8 +23,8 @@ class Api::V1::ChatConversationController < Api::BaseController
render json: chat_conversation_account, each_serializer: REST::ChatConversationAccountSerializer
end
def mark_chat_conversation_unread
@chat_conversation_account.update!(unread_count: 1)
def mark_chat_conversation_read
@chat_conversation_account.update!(unread_count: 0)
render json: @chat_conversation_account, serializer: REST::ChatConversationAccountSerializer
end
@@ -34,8 +34,13 @@ class Api::V1::ChatConversationController < Api::BaseController
end
def mark_chat_conversation_approved
@chat_conversation_account.update!(is_approved: true)
render json: @chat_conversation_account, serializer: REST::ChatConversationAccountSerializer
approved_conversation_count = ChatConversationAccount.where(account: @account, is_hidden: false, is_approved: true).count
if approved_conversation_count >= ChatConversationAccount::PER_ACCOUNT_APPROVED_LIMIT
render json: { error: true, message: "You have #{approved_conversation_count} active chat conversations. The limit is #{ChatConversationAccount::PER_ACCOUNT_APPROVED_LIMIT}. Delete some conversations first before approving any more requests." }
else
@chat_conversation_account.update!(is_approved: true)
render json: @chat_conversation_account, serializer: REST::ChatConversationAccountSerializer
end
end
private

View File

@@ -11,24 +11,16 @@ class Api::V1::ChatConversations::MessagesController < Api::BaseController
after_action :insert_pagination_headers, unless: -> { @chats.empty? }
def show
puts "tilly chat_message_conversations - 1: " + @chats.count.inspect
render json: @chats, each_serializer: REST::ChatMessageSerializer
end
def destroy_all
puts "tilly destry all chat"
# : todo :
# check if is pro
# @chat = ChatMessage.where(from_account: current_user.account).find(params[:id])
puts "tilly @chat: " + @chat.inspect
# : todo :
# make sure last_chat_message_id in chat_account_conversation gets set to last
# @chat.destroy!
# render json: @chat, serializer: REST::ChatMessageSerializer
if current_user.account.is_pro
@chat_conversation_account = PurgeChatMessagesService.new.call(current_user.account, @chat_conversation)
render json: @chat_conversation_account, serializer: REST::ChatConversationAccountSerializer
else
render json: { error: 'You need to be a GabPRO member to access this' }, status: 422
end
end
private

View File

@@ -5,50 +5,20 @@ class Api::V1::ChatMessagesController < Api::BaseController
before_action -> { doorkeeper_authorize! :write, :'write:chats' }
before_action :require_user!
before_action :set_chat_conversation, only: :create
before_action :set_chat_conversation_recipients, only: :create
def create
@chat = ChatMessage.create!(
from_account: current_account,
chat_conversation: @chat_conversation,
text: ActionController::Base.helpers.strip_tags(params[:text])
)
# : todo :
# check if blocked
# update unread_count++ if offline
@chat_conversation_recipients.each do |account|
payload = InlineRenderer.render(@chat, account, :chat_message)
Redis.current.publish("chat_messages:#{account.id}", Oj.dump(event: :notification, payload: payload))
end
@chat_conversation = ChatConversation.find(chat_params[:chat_conversation_id])
@chat = PostChatMessageService.new.call(current_user.account, text: chat_params[:text], chat_conversation: @chat_conversation)
render json: @chat, serializer: REST::ChatMessageSerializer
end
def destroy
@chat = ChatMessage.where(from_account: current_user.account).find(params[:id])
# : todo :
# make sure last_chat_message_id in chat_account_conversation gets set to last
@chat.destroy!
@chat = DeleteChatMessageService.new.call(current_user.account, params[:id])
render json: @chat, serializer: REST::ChatMessageSerializer
end
private
def set_chat_conversation
@chat_conversation = ChatConversation.find(params[:chat_conversation_id])
end
def set_chat_conversation_recipients
account_conversation = ChatConversationAccount.where(account: current_user.account, chat_conversation: @chat_conversation).first
@chat_conversation_recipients = Account.where(id: account_conversation.participant_account_ids)
end
def chat_params
params.permit(:text, :chat_conversation_id)
end

View File

@@ -46,7 +46,7 @@ class Api::V1::GroupsController < Api::BaseController
@groups = []
if !@groupCategory.nil?
@groups = Group.where(is_archived: false, group_categories: @groupCategory).all
@groups = Group.where(is_archived: false, group_categories: @groupCategory).order('member_count DESC').all
end
render json: @groups, each_serializer: REST::GroupSerializer
@@ -59,7 +59,7 @@ class Api::V1::GroupsController < Api::BaseController
@groups = []
if !params[:tag].empty?
@groups = Group.where(is_archived: false).where("array_to_string(tags, '||') ILIKE :tag", tag: "%#{params[:tag]}%").all
@groups = Group.where(is_archived: false).where("array_to_string(tags, '||') ILIKE :tag", tag: "%#{params[:tag]}%").order('member_count DESC').all
end
render json: @groups, each_serializer: REST::GroupSerializer

View File

@@ -62,6 +62,6 @@ class Api::V1::Timelines::HomeController < Api::BaseController
end
def regeneration_in_progress?
Redis.current.exists("account:#{current_account.id}:regeneration")
Redis.current.exists?("account:#{current_account.id}:regeneration")
end
end

View File

@@ -48,7 +48,25 @@ class EmptyController < ActionController::Base
nil
end
protected
def cache_collection(raw, klass)
return raw unless klass.respond_to?(:with_includes)
raw = raw.cache_ids.to_a if raw.is_a?(ActiveRecord::Relation)
cached_keys_with_value = Rails.cache.read_multi(*raw).transform_keys(&:id)
uncached_ids = raw.map(&:id) - cached_keys_with_value.keys
klass.reload_stale_associations!(cached_keys_with_value.values) if klass.respond_to?(:reload_stale_associations!)
unless uncached_ids.empty?
uncached = klass.where(id: uncached_ids).with_includes.each_with_object({}) { |item, h| h[item.id] = item }
uncached.each_value do |item|
Rails.cache.write(item, item)
end
end
raw.map { |item| cached_keys_with_value[item.id] || uncached[item.id] }.compact
end
def limit_param(default_limit)
return default_limit unless params[:limit]

View File

@@ -3,7 +3,7 @@
class ManifestsController < EmptyController
def show
render json: InstancePresenter.new, serializer: ManifestSerializer
render json:{} # InstancePresenter.new, serializer: ManifestSerializer
end
end

View File

@@ -20,7 +20,13 @@ class Settings::ProfilesController < Settings::BaseController
if @account.is_verified && params[:account][:display_name] && @account.display_name != params[:account][:display_name]
flash[:alert] = 'Unable to change Display name for verified account'
redirect_to settings_profile_path
elsif !@account.is_pro && params[:account][:username] && @account.username != params[:account][:username]
flash[:alert] = 'Unable to change username for your account. You are not GabPRO'
redirect_to settings_profile_path
else
# : todo :
# only allowed to change username once per day
if UpdateAccountService.new.call(@account, account_params)
redirect_to settings_profile_path, notice: I18n.t('generic.changes_saved_msg')
else
@@ -33,7 +39,7 @@ class Settings::ProfilesController < Settings::BaseController
private
def account_params
params.require(:account).permit(:display_name, :note, :avatar, :header, :locked, :bot, :discoverable, fields_attributes: [:name, :value])
params.require(:account).permit(:display_name, :username, :note, :avatar, :header, :locked, :bot, :discoverable, fields_attributes: [:name, :value])
end
def set_account

View File

@@ -46,11 +46,11 @@ class Settings::PromotionsController < Admin::BaseController
@promotion = Promotion.find(params[:id])
end
def set_filter_params
@filter_params = filter_params.to_hash.symbolize_keys
end
def set_filter_params
@filter_params = filter_params.to_hash.symbolize_keys
end
def resource_params
params.require(:promotion).permit(:expires_at, :status_id, :timeline_id, :position)
end
def resource_params
params.require(:promotion).permit(:expires_at, :status_id, :timeline_id, :position)
end
end

View File

@@ -0,0 +1,10 @@
class Settings::TrendingHashtagsController < Admin::BaseController
def index
@trending_hashtags = Redis.current.get("admin_trending_hashtags") || ''
end
def create
Redis.current.set("admin_trending_hashtags", params[:trending_hashtags])
redirect_to settings_trending_hashtags_path
end
end

View File

@@ -1,10 +1,10 @@
class Settings::Verifications::ModerationController < Admin::BaseController
def index
@verification_requests = AccountVerificationRequest.all
@verification_requests = AccountVerificationRequest.order('created_at DESC').all
end
def approve
verification_request = AccountVerificationRequest.find params[:id]
verification_request = AccountVerificationRequest.find(params[:id])
# Mark user as verified
account = verification_request.account
@@ -22,6 +22,8 @@ class Settings::Verifications::ModerationController < Admin::BaseController
end
def reject
@verification_requests = AccountVerificationRequest.find params[:id]
verification_request = AccountVerificationRequest.find(params[:id])
verification_request.destroy()
redirect_to settings_verifications_moderation_url, notice: I18n.t('verifications.moderation.rejected_msg')
end
end