Dismiss cache if cfgDate has changed (#2508)

2620-ppolicy-binding
Christophe Maudoux 4 years ago
parent 8ae9985e7c
commit 6be4cfe035
  1. 4
      lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf.pm
  2. 58
      lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf.pm
  3. 2
      lemonldap-ng-manager/site/coffee/manager.coffee
  4. 2
      lemonldap-ng-manager/site/htdocs/static/js/manager.js
  5. 2
      lemonldap-ng-manager/site/htdocs/static/js/manager.min.js
  6. 2
      lemonldap-ng-manager/site/htdocs/static/js/manager.min.js.map
  7. 10
      lemonldap-ng-manager/t/16-cli.t

@ -122,7 +122,9 @@ sub saveConf {
# If configuration was modified, return an error # If configuration was modified, return an error
if ( not $args{force} ) { if ( not $args{force} ) {
return CONFIG_WAS_CHANGED if ( $conf->{cfgNum} != $last ); return CONFIG_WAS_CHANGED
if ( $conf->{cfgNum} ne $last
|| $args{cfgDate} && $args{cfgDate} ne $args{currentCfgDate} );
return DATABASE_LOCKED if ( $self->isLocked() or not $self->lock() ); return DATABASE_LOCKED if ( $self->isLocked() or not $self->lock() );
} }
$conf->{cfgNum} = $last + 1 unless ( $args{cfgNumFixed} ); $conf->{cfgNum} = $last + 1 unless ( $args{cfgNumFixed} );

@ -123,7 +123,7 @@ sub newRSAKey {
my $keys = { my $keys = {
'private' => $rsa->get_private_key_string(), 'private' => $rsa->get_private_key_string(),
'public' => $rsa->get_public_key_x509_string(), 'public' => $rsa->get_public_key_x509_string(),
'hash' => md5_base64($rsa->get_public_key_string()), 'hash' => md5_base64( $rsa->get_public_key_string() ),
}; };
if ( $query->{password} ) { if ( $query->{password} ) {
my $pem = Convert::PEM->new( my $pem = Convert::PEM->new(
@ -345,26 +345,25 @@ sub newConf {
# Body must be json # Body must be json
my $new = $req->jsonBodyToObj; my $new = $req->jsonBodyToObj;
unless ( defined($new) ) { return $self->sendError( $req, undef, 400 ) unless ( defined $new );
return $self->sendError( $req, undef, 400 );
}
# Verify that cfgNum has been asked # Verify that cfgNum has been sent
unless ( defined $req->params('cfgNum') ) { return $self->sendError( $req, "Missing configuration number", 400 )
return $self->sendError( $req, "Missing configuration number", 400 ); unless ( defined $req->params('cfgNum') );
}
# # Verify that cfgDate has been sent
# return $self->sendError( $req, "Missing configuration date", 400 )
# unless ( defined $req->params('cfgDate') );
# Set current conf to cfgNum # Set current conf to cfgNum
unless ( defined $self->getConfByNum( $req->params('cfgNum') ) ) { return $self->sendError(
return $self->sendError( $req,
$req, "Configuration "
"Configuration " . $req->params('cfgNum')
. $req->params('cfgNum') . " not available "
. " not available " . $Lemonldap::NG::Common::Conf::msg,
. $Lemonldap::NG::Common::Conf::msg, 400
400 ) unless ( defined $self->getConfByNum( $req->params('cfgNum') ) );
);
}
# Parse new conf # Parse new conf
require Lemonldap::NG::Manager::Conf::Parser; require Lemonldap::NG::Manager::Conf::Parser;
@ -372,13 +371,20 @@ sub newConf {
{ tree => $new, refConf => $self->currentConf, req => $req } ); { tree => $new, refConf => $self->currentConf, req => $req } );
# If ref conf isn't last conf, consider conf changed # If ref conf isn't last conf, consider conf changed
my $cfgNum = $self->confAcc->lastCfg; my $currentCfgNum = $self->confAcc->lastCfg;
unless ( defined $cfgNum ) { $req->error($Lemonldap::NG::Common::Conf::msg)
$req->error($Lemonldap::NG::Common::Conf::msg); unless ( defined $currentCfgNum );
}
return $self->sendError( $req, undef, 400 ) if ( $req->error ); return $self->sendError( $req, undef, 400 ) if ( $req->error );
my $currentConf =
if ( $cfgNum ne $req->params('cfgNum') ) { $parser->confChanged(1); } $self->confAcc->getConf(
{ CfgNum => $currentCfgNum, raw => 1, noCache => 1 } );
my $currentCfgDate = $currentConf->{cfgDate};
$self->logger->debug(
"Current CfgNum/cfgDate: $currentCfgNum/$currentCfgDate");
$parser->confChanged(1)
if ( $currentCfgNum ne $req->params('cfgNum')
|| $req->params('cfgDate')
&& $req->params('cfgDate') ne $currentCfgDate );
my $res = { result => $parser->check( $self->p ) }; my $res = { result => $parser->check( $self->p ) };
@ -402,6 +408,10 @@ sub newConf {
else { else {
my %args; my %args;
$args{force} = 1 if ( $req->params('force') ); $args{force} = 1 if ( $req->params('force') );
if ( $req->params('cfgDate') ) {
$args{cfgDate} = $req->params('cfgDate');
$args{currentCfgDate} = $currentCfgDate;
}
my $s = CONFIG_WAS_CHANGED; my $s = CONFIG_WAS_CHANGED;
$s = $self->confAcc->saveConf( $parser->newConf, %args ) $s = $self->confAcc->saveConf( $parser->newConf, %args )
unless ( @{ $parser->{needConfirmation} } && !$args{force} ); unless ( @{ $parser->{needConfirmation} } && !$args{force} );

@ -189,7 +189,7 @@ llapp.controller 'TreeCtrl', [
id: "cfgLog" id: "cfgLog"
title: "cfgLog" title: "cfgLog"
data: if $scope.result then $scope.result else '' data: if $scope.result then $scope.result else ''
$http.post("#{window.confPrefix}?cfgNum=#{$scope.currentCfg.cfgNum}#{if $scope.forceSave then "&force=1" else ''}", $scope.data).then (response) -> $http.post("#{window.confPrefix}?cfgNum=#{$scope.currentCfg.cfgNum}&cfgDate=#{$scope.currentCfg.cfgDate}#{if $scope.forceSave then "&force=1" else ''}", $scope.data).then (response) ->
$scope.data.pop() $scope.data.pop()
_checkSaveResponse response.data _checkSaveResponse response.data
,(response) -> ,(response) ->

@ -225,7 +225,7 @@ This file contains:
title: "cfgLog", title: "cfgLog",
data: $scope.result ? $scope.result : '' data: $scope.result ? $scope.result : ''
}); });
return $http.post(window.confPrefix + "?cfgNum=" + $scope.currentCfg.cfgNum + ($scope.forceSave ? "&force=1" : ''), $scope.data).then(function(response) { return $http.post(window.confPrefix + "?cfgNum=" + $scope.currentCfg.cfgNum + "&cfgDate=" + $scope.currentCfg.cfgDate + ($scope.forceSave ? "&force=1" : ''), $scope.data).then(function(response) {
$scope.data.pop(); $scope.data.pop();
return _checkSaveResponse(response.data); return _checkSaveResponse(response.data);
}, function(response) { }, function(response) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -4,7 +4,7 @@ use JSON;
use strict; use strict;
require 't/test-lib.pm'; require 't/test-lib.pm';
my $tests = 18; my $tests = 17;
use_ok('Lemonldap::NG::Common::Cli'); use_ok('Lemonldap::NG::Common::Cli');
use_ok('Lemonldap::NG::Manager::Cli'); use_ok('Lemonldap::NG::Manager::Cli');
@ -77,14 +77,6 @@ combined_like(
'"Force cfgNum" OK' '"Force cfgNum" OK'
); );
# Test 'set' command with nohistory
@cmd = qw(-yes 1 -force 1 -nohistory 1 set cookieName test);
combined_like(
sub { llclient->run(@cmd) },
qr#cfgNum forced with 6#s,
'"Force cfgNum" OK'
);
# Test 'info' command with force # Test 'info' command with force
@cmd = qw(info); @cmd = qw(info);
combined_like( combined_like(

Loading…
Cancel
Save