<p></p>
<p><b>@tomhughes</b> commented on this pull request.</p>

<hr>

<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/5069#discussion_r1715712438">app/controllers/user_blocks_controller.rb</a>:</p>
<pre style='color:#555'>>        else
-        render :action => "edit"
+        user_block_was_active = @user_block.active?
+        @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)
</pre>
<p dir="auto">I don't think this needs parentheses does it?</p>

<hr>

<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/5069#discussion_r1715712795">app/controllers/user_blocks_controller.rb</a>:</p>
<pre style='color:#555'>>        else
-        render :action => "edit"
+        user_block_was_active = @user_block.active?
+        @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)
+        if !user_block_was_active && !@user_block.active?
+          @user_block.ends_at = @user_block.ends_at_was
+          @user_block.deactivates_at = @user_block.deactivates_at_was
+        end
+        @user_block.deactivates_at = [@user_block.ends_at, @user_block.updated_at].max if !@user_block.deactivates_at && !@user_block.needs_view
+
+        if @user_block.save
+          flash[:notice] = t(".success")
+          redirect_to(@user_block)
</pre>
<p dir="auto">Does this needs parentheses?</p>

<hr>

<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/5069#discussion_r1715714691">app/controllers/user_blocks_controller.rb</a>:</p>
<pre style='color:#555'>>        else
-        render :action => "edit"
+        user_block_was_active = @user_block.active?
+        @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)
+        if !user_block_was_active && !@user_block.active?
+          @user_block.ends_at = @user_block.ends_at_was
+          @user_block.deactivates_at = @user_block.deactivates_at_was
+        end
+        @user_block.deactivates_at = [@user_block.ends_at, @user_block.updated_at].max if !@user_block.deactivates_at && !@user_block.needs_view
</pre>
<p dir="auto">I don't think this needs both conditions does it? The only way <code class="notranslate">deactivates_at</code> can be unset is it <code class="notranslate">needs_view</code> is false?</p>
<p dir="auto">The whole logic here is really hard to grasp and reason about to be honest and I wonder if there's a better way to do it or if we should even be allowing all the cases this is allowing - should we be allowed an expired block to be reactivated?</p>

<hr>

<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/5069#discussion_r1715717547">app/helpers/user_blocks_helper.rb</a>:</p>
<pre style='color:#555'>> @@ -20,7 +20,7 @@ def block_status(block)
       # 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
</pre>
<p dir="auto">Do we need the second half of this? It's just for old blocks because we're not backfilling <code class="notranslate">deactivates_at</code> for them?</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/5069#pullrequestreview-2236228362">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLP75BLGP53XDAJU33DZRJDMHAVCNFSM6AAAAABMOBVSWOVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDEMZWGIZDQMZWGI">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLLKOPKHWDVD7BO6VH3ZRJDMHA5CNFSM6AAAAABMOBVSWOWGG33NNVSW45C7OR4XAZNRKB2WY3CSMVYXKZLTORJGK5TJMV32UY3PNVWWK3TUL5UWJTUFJIRQU.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/pull/5069/review/2236228362</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/5069#pullrequestreview-2236228362",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/5069#pullrequestreview-2236228362",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>