Swap url_escape string shenanigans for proper Mojo route methods
This commit is contained in:
parent
a7e848d4a1
commit
a4f1f18cb4
|
@ -3,7 +3,6 @@
|
||||||
use Module::Installed::Tiny qw(module_installed);
|
use Module::Installed::Tiny qw(module_installed);
|
||||||
|
|
||||||
use Mojolicious::Lite -signatures;
|
use Mojolicious::Lite -signatures;
|
||||||
use Mojo::Util qw(url_unescape);
|
|
||||||
|
|
||||||
use Readonly;
|
use Readonly;
|
||||||
|
|
||||||
|
@ -250,7 +249,7 @@ sub user_has_permission_on_path ($user, $permission, $path) {
|
||||||
my $permit = $rule_ref->[1];
|
my $permit = $rule_ref->[1];
|
||||||
my $permission = $PERMISSIONS{$permission};
|
my $permission = $PERMISSIONS{$permission};
|
||||||
|
|
||||||
next if not $path->to_string =~ m/$regex/;
|
next if not $path->to_route =~ m/$regex/;
|
||||||
|
|
||||||
return ( $permission & $permit ) == $permission;
|
return ( $permission & $permit ) == $permission;
|
||||||
}
|
}
|
||||||
|
@ -287,7 +286,6 @@ sub get_sorts_hash_from_query ($query_string) {
|
||||||
sub turn_string_into_path_using_url ($string, $url) {
|
sub turn_string_into_path_using_url ($string, $url) {
|
||||||
my $path = $url->path->clone->merge($string);
|
my $path = $url->path->clone->merge($string);
|
||||||
$path = sanitize_path($path);
|
$path = sanitize_path($path);
|
||||||
$path = unescape_path($path);
|
|
||||||
$path = $path->trailing_slash(0);
|
$path = $path->trailing_slash(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,7 +313,7 @@ sub user_save_file_to_path ($user, $file, $path) {
|
||||||
my ( $code, $message ) = check_user_can_create_file($user, $path);
|
my ( $code, $message ) = check_user_can_create_file($user, $path);
|
||||||
return $code, $message if $code != 200;
|
return $code, $message if $code != 200;
|
||||||
|
|
||||||
my $path_string = $ROOT_DIRECTORY . $path->to_string;
|
my $path_string = $ROOT_DIRECTORY . $path->to_route;
|
||||||
$file->move_to($path_string)
|
$file->move_to($path_string)
|
||||||
or return 500, "Could not upload file '$path_string'!";
|
or return 500, "Could not upload file '$path_string'!";
|
||||||
|
|
||||||
|
@ -326,7 +324,7 @@ sub user_mkdir_at_path ($user, $path) {
|
||||||
my ( $code, $message ) = check_user_can_create_file($user, $path);
|
my ( $code, $message ) = check_user_can_create_file($user, $path);
|
||||||
return $code, $message if $code != 200;
|
return $code, $message if $code != 200;
|
||||||
|
|
||||||
my $path_string = $ROOT_DIRECTORY . $path->to_string;
|
my $path_string = $ROOT_DIRECTORY . $path->to_route;
|
||||||
mkdir($path_string)
|
mkdir($path_string)
|
||||||
or return 500, "Directory '$path_string' could not be created!";
|
or return 500, "Directory '$path_string' could not be created!";
|
||||||
|
|
||||||
|
@ -337,7 +335,7 @@ sub user_delete_path ($user, $path) {
|
||||||
my ( $code, $message ) = check_user_can_delete_file($user, $path);
|
my ( $code, $message ) = check_user_can_delete_file($user, $path);
|
||||||
return $code, $message if $code != 200;
|
return $code, $message if $code != 200;
|
||||||
|
|
||||||
my $path_string = $ROOT_DIRECTORY . $path->to_string;
|
my $path_string = $ROOT_DIRECTORY . $path->to_route;
|
||||||
my $err = 0;
|
my $err = 0;
|
||||||
if ( -d $path_string ) {
|
if ( -d $path_string ) {
|
||||||
$err = not rmtree($path_string);
|
$err = not rmtree($path_string);
|
||||||
|
@ -360,8 +358,8 @@ sub user_move_path_to_path ($user, $path, $new_path) {
|
||||||
( $code, $message ) = check_user_can_create_file($user, $new_path);
|
( $code, $message ) = check_user_can_create_file($user, $new_path);
|
||||||
return $code, $message if $code != 200;
|
return $code, $message if $code != 200;
|
||||||
|
|
||||||
my $path_string = $ROOT_DIRECTORY . $path->to_string;
|
my $path_string = $ROOT_DIRECTORY . $path->to_route;
|
||||||
my $new_path_string = $ROOT_DIRECTORY . $new_path->to_string;
|
my $new_path_string = $ROOT_DIRECTORY . $new_path->to_route;
|
||||||
move($path_string, $new_path_string)
|
move($path_string, $new_path_string)
|
||||||
or return 500,
|
or return 500,
|
||||||
"Could not move file '$path_string' to '$new_path_string'!";
|
"Could not move file '$path_string' to '$new_path_string'!";
|
||||||
|
@ -370,7 +368,7 @@ sub user_move_path_to_path ($user, $path, $new_path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_files_at_path ($path) {
|
sub get_files_at_path ($path) {
|
||||||
my $path_string = $path->to_string;
|
my $path_string = $path->to_route;
|
||||||
my $directory_path = $ROOT_DIRECTORY . $path_string;
|
my $directory_path = $ROOT_DIRECTORY . $path_string;
|
||||||
|
|
||||||
opendir my $directory, $directory_path or return ();
|
opendir my $directory, $directory_path or return ();
|
||||||
|
@ -424,14 +422,6 @@ sub sort_symbol_for_order ($sort_order) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub unescape_path ($path) {
|
|
||||||
my $path_string = $path->to_string;
|
|
||||||
|
|
||||||
$path_string = url_unescape($path_string);
|
|
||||||
|
|
||||||
return Mojo::Path->new($path_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub get_file_with_name ($name) {
|
sub get_file_with_name ($name) {
|
||||||
my (
|
my (
|
||||||
$device, $inode, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
|
$device, $inode, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
|
||||||
|
@ -446,21 +436,21 @@ sub get_file_with_name ($name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
my %file = (
|
my %file = (
|
||||||
name => $name,
|
name => $name,
|
||||||
device => $device,
|
device => $device,
|
||||||
inode => $inode,
|
inode => $inode,
|
||||||
mode => $mode,
|
mode => $mode,
|
||||||
nlink => $nlink,
|
nlink => $nlink,
|
||||||
uid => $uid,
|
uid => $uid,
|
||||||
gid => $gid,
|
gid => $gid,
|
||||||
rdev => $rdev,
|
rdev => $rdev,
|
||||||
size => $size,
|
size => $size,
|
||||||
atime => $atime,
|
atime => $atime,
|
||||||
mtime => $mtime,
|
mtime => $mtime,
|
||||||
ctime => $ctime,
|
ctime => $ctime,
|
||||||
blksize => $blksize,
|
blksize => $blksize,
|
||||||
blocks => $blocks,
|
blocks => $blocks,
|
||||||
type => $type,
|
type => $type,
|
||||||
);
|
);
|
||||||
|
|
||||||
return \%file;
|
return \%file;
|
||||||
|
@ -550,7 +540,7 @@ sub parse_sort_query ($query_string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_user_can_create_file ($user, $path) {
|
sub check_user_can_create_file ($user, $path) {
|
||||||
my $path_string = $path->to_string;
|
my $path_string = $path->to_route;
|
||||||
|
|
||||||
if ( not user_has_permission_on_path($user, 'CREATE', $path) ) {
|
if ( not user_has_permission_on_path($user, 'CREATE', $path) ) {
|
||||||
return 403, "You do not have permission to create '$path_string'!";
|
return 403, "You do not have permission to create '$path_string'!";
|
||||||
|
@ -560,7 +550,7 @@ sub check_user_can_create_file ($user, $path) {
|
||||||
return 409, "'$path_string' already exists!";
|
return 409, "'$path_string' already exists!";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $parent = $path->to_dir->to_string;
|
my $parent = $path->to_dir->to_route;
|
||||||
|
|
||||||
if ( not -e $ROOT_DIRECTORY . $parent ) {
|
if ( not -e $ROOT_DIRECTORY . $parent ) {
|
||||||
return 409, "Parent directory '$parent' does not exist!";
|
return 409, "Parent directory '$parent' does not exist!";
|
||||||
|
@ -574,7 +564,7 @@ sub check_user_can_create_file ($user, $path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_user_can_delete_file ($user, $path) {
|
sub check_user_can_delete_file ($user, $path) {
|
||||||
my $path_string = $path->to_string;
|
my $path_string = $path->to_route;
|
||||||
|
|
||||||
if ( not user_has_permission_on_path($user, 'DELETE', $path) ) {
|
if ( not user_has_permission_on_path($user, 'DELETE', $path) ) {
|
||||||
return 403, "You do not have permission to delete '$path_string'!";
|
return 403, "You do not have permission to delete '$path_string'!";
|
||||||
|
|
|
@ -68,4 +68,4 @@ function get_file_name_from_url(url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue