]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/user_blocks_controller.rb
Call paging heading helpers from partial
[rails.git] / app / controllers / user_blocks_controller.rb
index 70dfddf83385cf40a7dd7f6994321c0f4d217f8d..546c8233c65a4d5f4eeb42d97cc76dc0558c1d28 100644 (file)
@@ -1,4 +1,6 @@
 class UserBlocksController < ApplicationController
+  include UserMethods
+
   layout "site"
 
   before_action :authorize_web
@@ -32,7 +34,7 @@ class UserBlocksController < ApplicationController
   end
 
   def edit
-    params[:user_block_period] = ((@user_block.ends_at - Time.now.getutc) / 1.hour).ceil.to_s
+    params[:user_block_period] = ((@user_block.ends_at - Time.now.utc) / 1.hour).ceil.to_s
   end
 
   def create
@@ -41,7 +43,7 @@ class UserBlocksController < ApplicationController
         :user => @user,
         :creator => current_user,
         :reason => params[:user_block][:reason],
-        :ends_at => Time.now.getutc + @block_period.hours,
+        :ends_at => Time.now.utc + @block_period.hours,
         :needs_view => params[:user_block][:needs_view]
       )
 
@@ -62,7 +64,7 @@ class UserBlocksController < ApplicationController
         flash[:error] = t(".only_creator_can_edit")
         redirect_to :action => "edit"
       elsif @user_block.update(
-        :ends_at => Time.now.getutc + @block_period.hours,
+        :ends_at => Time.now.utc + @block_period.hours,
         :reason => params[:user_block][:reason],
         :needs_view => params[:user_block][:needs_view]
       )
@@ -79,11 +81,9 @@ class UserBlocksController < ApplicationController
   ##
   # revokes the block, setting the end_time to now
   def revoke
-    if params[:confirm]
-      if @user_block.revoke! current_user
-        flash[:notice] = t ".flash"
-        redirect_to(@user_block)
-      end
+    if request.post? && params[:confirm] && @user_block.revoke!(current_user)
+      flash[:notice] = t ".flash"
+      redirect_to(@user_block)
     end
   end
 
@@ -128,7 +128,7 @@ class UserBlocksController < ApplicationController
     @block_period = params[:user_block_period].to_i
     @valid_params = false
 
-    if !UserBlock::PERIODS.include?(@block_period)
+    if UserBlock::PERIODS.exclude?(@block_period)
       flash[:error] = t("user_blocks.filter.block_period")
 
     elsif @user_block && !@user_block.active?