mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-20 00:35:22 +00:00
Add cache clear ubutton
This commit is contained in:
parent
b3c40028d4
commit
5597574dad
4 changed files with 27 additions and 1 deletions
11
app/controllers/admin/cache_controller.rb
Normal file
11
app/controllers/admin/cache_controller.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
class Admin::CacheController < Admin::BaseController
|
||||
def clear
|
||||
unless current_user&.admin_level_superadmin?
|
||||
redirect_to root_path, alert: "Not authorized"
|
||||
return
|
||||
end
|
||||
|
||||
Rails.cache.clear
|
||||
redirect_back fallback_location: root_path, notice: "Cache cleared successfully"
|
||||
end
|
||||
end
|
||||
|
|
@ -13,7 +13,9 @@ class InertiaController < ApplicationController
|
|||
csrf_token: form_authenticity_token,
|
||||
signout_path: signout_path,
|
||||
show_stop_impersonating: session[:impersonater_user_id].present?,
|
||||
stop_impersonating_path: stop_impersonating_path
|
||||
stop_impersonating_path: stop_impersonating_path,
|
||||
is_superadmin: current_user&.admin_level_superadmin? || false,
|
||||
clear_cache_path: current_user&.admin_level_superadmin? ? admin_clear_cache_path : nil
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,8 @@
|
|||
signout_path: string;
|
||||
show_stop_impersonating: boolean;
|
||||
stop_impersonating_path: string;
|
||||
is_superadmin: boolean;
|
||||
clear_cache_path?: string | null;
|
||||
};
|
||||
|
||||
let { layout, children }: { layout: LayoutProps; children?: () => unknown } =
|
||||
|
|
@ -313,6 +315,16 @@
|
|||
{/if}
|
||||
</a>
|
||||
{/each}
|
||||
|
||||
{#if layout.is_superadmin && layout.clear_cache_path}
|
||||
<a
|
||||
href={layout.clear_cache_path}
|
||||
onclick={(e) => { e.preventDefault(); router.post(layout.clear_cache_path); }}
|
||||
class="{navLinkClass(false)} superadmin-tool cursor-pointer"
|
||||
>
|
||||
Clear cache
|
||||
</a>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ Rails.application.routes.draw do
|
|||
post :toggle_verified
|
||||
end
|
||||
end
|
||||
post :clear_cache, to: "cache#clear", as: :clear_cache
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue