From 75c6cd9fc23c966569195bf5c9f71f411df9f84b Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Wed, 23 Dec 2020 15:00:30 -0500 Subject: [PATCH] Updated PostStatusService to allow group comments without joining group MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Updated: - PostStatusService to allow group comments without joining group --- app/services/post_status_service.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index f399c183..ed818488 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -124,12 +124,26 @@ class PostStatusService < BaseService def validate_group! group_id = @options[:group_id] + # All good if no group return if group_id.blank? + + # If removed from group, return error immediately + if GroupRemovedAccount.where(account: @account, group_id: group_id).exists? + raise GabSocial::ValidationError, I18n.t('statuses.not_a_member_of_group') + return + end + + # Return ok if autojoin flag exists return if @autoJoinGroup - # : todo : check removedaccounts if exist dont allow + # Return ok if is reply + return unless @in_reply_to.nil? - raise GabSocial::ValidationError, I18n.t('statuses.not_a_member_of_group') if not GroupAccount.where(account: @account, group_id: group_id).exists? + # If is normal post and tries without being a member, return error + unless GroupAccount.where(account: @account, group_id: group_id).exists? + raise GabSocial::ValidationError, I18n.t('statuses.not_a_member_of_group') + return + end end def validate_media!