Skip to content

Commit

Permalink
Forbid server editing if MIRROR_PROVIDER is configured
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-suse committed Oct 9, 2023
1 parent eda5d88 commit 84b349e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
6 changes: 5 additions & 1 deletion assets/javascripts/admintable.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,11 @@ function renderAdminTableActions(data, type, row, meta) {
return '';
}
var url = $("#admintable_api_url").val();
res = '<button type="submit" class="btn" alt="Edit" title="Edit" onclick="setEditingAdminTableRow(this.parentElement, true, false);"><i class="far fa-edit"></i></button>';
var noActions = document.getElementById("regionmirrorproviderpanel");
var res = '';
if (! noActions ) {
res = '<button type="submit" class="btn" alt="Edit" title="Edit" onclick="setEditingAdminTableRow(this.parentElement, true, false);"><i class="far fa-edit"></i></button>';
}
if (url == '/rest/server' && data) {
return res + '<button type="submit" class="btn" alt="UpdateLocation" title="Update Location" onclick="submitServerLocationRow(this.parentElement, ' + data + ');"><i class="far fa-bookmark"></i></button>';
} else {
Expand Down
12 changes: 11 additions & 1 deletion lib/MirrorCache/WebAPI/Controller/App/Myserver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ package MirrorCache::WebAPI::Controller::App::Myserver;
use Mojo::Base 'MirrorCache::WebAPI::Controller::App::Table';

sub index {
shift->SUPER::admintable('myserver');
my $c = shift;
my $mirror_provider = $c->mcconfig->mirror_provider;
if (my $url = $c->mcconfig->mirror_provider) {
$url =~ s!^https?://(?:www\.)?!!i;
$url =~ s!/.*!!;
$url =~ s/[\?\#\:].*//;
my $mirror_provider_url = 'https://' . $url . '/app/server';
$c->stash( mirror_provider_url => $mirror_provider_url );
}

$c->SUPER::admintable('myserver');
}

sub update {
Expand Down
12 changes: 11 additions & 1 deletion lib/MirrorCache/WebAPI/Controller/App/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ package MirrorCache::WebAPI::Controller::App::Server;
use Mojo::Base 'MirrorCache::WebAPI::Controller::App::Table';

sub index {
shift->SUPER::admintable('server');
my $c = shift;
my $mirror_provider = $c->mcconfig->mirror_provider;
if (my $url = $c->mcconfig->mirror_provider) {
$url =~ s!^https?://(?:www\.)?!!i;
$url =~ s!/.*!!;
$url =~ s/[\?\#\:].*//;
my $mirror_provider_url = 'https://' . $url . '/app/server';
$c->stash( mirror_provider_url => $mirror_provider_url );
}

$c->SUPER::admintable('server');
}

sub update {
Expand Down
3 changes: 0 additions & 3 deletions t/environ/01-smoke-mirror-provider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ mcnaeast=$(environ mc2 $(pwd))
ap8=$(environ ap8)
ap7=$(environ ap7)

$mcmirror/gen_env MIRRORCACHE_MODE=mirror_provider


$mcmirror/start

$mcmirror/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap7/print_address)','','t','us','na'"
Expand Down
7 changes: 6 additions & 1 deletion templates/app/myserver/index.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
</div>

%= include 'layouts/info'
% if (eval ('$mirror_provider_url')) {
<div id="regionmirrorproviderpanel" class="card">
<span>This view is readonly, it is imported from <a href=<%= eval('$mirror_provider_url') %>>mirror provider</a></span>
</div>
% }

<table id="myservers" class="admintable table table-striped">
<thead>
Expand All @@ -38,7 +43,7 @@
<tbody>
</tbody>
</table>
% if (current_user) {
% if (current_user && !eval('$mirror_provider_url')) {
<div class="text-center">
<input value="New mirror" onclick="addAdminTableRow();" type="button" class="btn btn-default"/>
</div>
Expand Down
7 changes: 6 additions & 1 deletion templates/app/server/index.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
</div>

%= include 'layouts/info'
% if (eval ('$mirror_provider_url')) {
<div id="regionmirrorproviderpanel" class="card">
<span>This view is readonly, it is imported from <a href=<%= eval('$mirror_provider_url') %>>mirror provider</a></span>
</div>
% }

<table id="servers" class="admintable table table-striped">
<thead>
Expand All @@ -38,7 +43,7 @@
<tbody>
</tbody>
</table>
% if (is_admin) {
% if (is_admin && !eval('$mirror_provider_url')) {
<div class="text-center">
<input value="New mirror" onclick="addAdminTableRow();" type="button" class="btn btn-default"/>
</div>
Expand Down

0 comments on commit 84b349e

Please sign in to comment.