Merge remote-tracking branch 'upstream/pull/5069'
This commit is contained in:
commit
754a0a9cb5
8 changed files with 165 additions and 15 deletions
|
@ -26,6 +26,7 @@ class UserBlocksController < ApplicationController
|
|||
def show
|
||||
if current_user && current_user == @user_block.user
|
||||
@user_block.needs_view = false
|
||||
@user_block.deactivates_at = [@user_block.ends_at, Time.now.utc].max
|
||||
@user_block.save!
|
||||
end
|
||||
end
|
||||
|
@ -49,6 +50,7 @@ class UserBlocksController < ApplicationController
|
|||
:ends_at => now + @block_period.hours,
|
||||
:needs_view => params[:user_block][:needs_view]
|
||||
)
|
||||
@user_block.deactivates_at = @user_block.ends_at unless @user_block.needs_view
|
||||
|
||||
if @user_block.save
|
||||
flash[:notice] = t(".flash", :name => @user.display_name)
|
||||
|
@ -72,12 +74,17 @@ class UserBlocksController < ApplicationController
|
|||
@user_block.reason = params[:user_block][:reason]
|
||||
@user_block.needs_view = params[:user_block][:needs_view]
|
||||
@user_block.ends_at = Time.now.utc + @block_period.hours
|
||||
@user_block.deactivates_at = (@user_block.ends_at unless @user_block.needs_view)
|
||||
@user_block.revoker = current_user if user_block_was_active && !@user_block.active?
|
||||
if !user_block_was_active && @user_block.active?
|
||||
flash.now[:error] = t(".inactive_block_cannot_be_reactivated")
|
||||
render :action => "edit"
|
||||
else
|
||||
@user_block.ends_at = @user_block.ends_at_was unless user_block_was_active
|
||||
unless user_block_was_active
|
||||
@user_block.ends_at = @user_block.ends_at_was
|
||||
@user_block.deactivates_at = @user_block.deactivates_at_was
|
||||
@user_block.deactivates_at = [@user_block.ends_at, @user_block.updated_at].max unless @user_block.deactivates_at # take updated_at into account before deactivates_at is backfilled
|
||||
end
|
||||
if @user_block.save
|
||||
flash[:notice] = t(".success")
|
||||
redirect_to @user_block
|
||||
|
|
|
@ -20,7 +20,7 @@ module UserBlocksHelper
|
|||
# the max of the last update time or the ends_at time is when this block finished
|
||||
# either because the user viewed the block (updated_at) or it expired or was
|
||||
# revoked (ends_at)
|
||||
last_time = [block.ends_at, block.updated_at].max
|
||||
last_time = block.deactivates_at || [block.ends_at, block.updated_at].max
|
||||
t("user_blocks.helper.time_past_html", :time => friendly_date_ago(last_time))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,16 +2,17 @@
|
|||
#
|
||||
# Table name: user_blocks
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# user_id :bigint(8) not null
|
||||
# creator_id :bigint(8) not null
|
||||
# reason :text not null
|
||||
# ends_at :datetime not null
|
||||
# needs_view :boolean default(FALSE), not null
|
||||
# revoker_id :bigint(8)
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# reason_format :enum default("markdown"), not null
|
||||
# id :integer not null, primary key
|
||||
# user_id :bigint(8) not null
|
||||
# creator_id :bigint(8) not null
|
||||
# reason :text not null
|
||||
# ends_at :datetime not null
|
||||
# needs_view :boolean default(FALSE), not null
|
||||
# revoker_id :bigint(8)
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# reason_format :enum default("markdown"), not null
|
||||
# deactivates_at :datetime
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
|
@ -28,6 +29,8 @@
|
|||
class UserBlock < ApplicationRecord
|
||||
validate :moderator_permissions
|
||||
validates :reason, :characters => true
|
||||
validates :deactivates_at, :comparison => { :greater_than_or_equal_to => :ends_at }, :unless => -> { needs_view }
|
||||
validates :deactivates_at, :absence => true, :if => -> { needs_view }
|
||||
|
||||
belongs_to :user, :class_name => "User"
|
||||
belongs_to :creator, :class_name => "User"
|
||||
|
@ -67,6 +70,7 @@ class UserBlock < ApplicationRecord
|
|||
def revoke!(revoker)
|
||||
update(
|
||||
:ends_at => Time.now.utc,
|
||||
:deactivates_at => Time.now.utc,
|
||||
:revoker_id => revoker.id,
|
||||
:needs_view => false
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue