Public projects are now created in the user\'s workspace directory instead of the main directory so project directories do not conflict with user folders

This commit is contained in:
xevidos 2019-07-08 13:44:17 -04:00
parent 4dab45e0e7
commit 0dedba59d2
4 changed files with 104 additions and 63 deletions

View file

@ -37,6 +37,12 @@ class Permissions {
$level = self::LEVELS[$level];
} else {
exit( formatJSEND( "error", "Access Level does not exist." ) );
}
} else {
if( ! in_array( $level, self::LEVELS ) ) {
exit( formatJSEND( "error", "Access Level does not exist." ) );
}
}
@ -46,19 +52,11 @@ class Permissions {
public static function check_path( $level, $path ) {
if( ! in_array( $level, array_keys( self::LEVELS ) ) ) {
exit( formatJSEND( "error", "Access Level does not exist." ) );
}
$pass = false;
$user_level = self::get_access( $path );
if( $user_level >= self::LEVELS[$level] ) {
echo var_dump( $level, $user_level, $path );
$pass = true;
}
return( $pass );
return self::check_access( $level, $user_level );
}
public static function get_access( $path ) {
@ -100,7 +98,7 @@ class Permissions {
}
}
//echo var_dump( $full_path, $full_project_path, $path_postition, $user["level"], $pass );
//echo var_dump( $full_path, $full_project_path, $path_postition, $user["level"], $data["owner"], $_SESSION["user"] );
if( $access > 0 ) {
break;

View file

@ -117,6 +117,7 @@ class Project extends Common {
public function check_duplicate( $full_path ) {
global $sql;
$pass = true;
$query = "SELECT id, path, owner FROM projects;";
$result = $sql->query( $query, array(), array(), "fetchAll" );
@ -231,6 +232,26 @@ class Project extends Common {
return( $return );
}
public function get_all_projects() {
if( is_admin() ) {
global $sql;
$query = "SELECT * FROM projects";
$bind_variables = array();
$return = $sql->query( $query, $bind_variables, array() );
if( empty( $return ) ) {
$return = formatJSEND( "error", "Error fetching projects." );
}
} else {
$return = formatJSEND( "error", "Only admins are allowed to view all projects." );
}
return( $return );
}
public function get_projects() {
global $sql;
@ -394,13 +415,14 @@ class Project extends Common {
}
if ( $this->path != '' ) {
if( ! $this->public_project && ! $this->isAbsPath( $this->path ) ) {
$user_path = WORKSPACE . '/' . preg_replace( '/[^\w-]/', '', strtolower( $_SESSION["user"] ) );
if( ! $this->isAbsPath( $this->path ) ) {
$this->path = $_SESSION["user"] . '/' . $this->path;
}
$pass = $this->check_duplicate();
$pass = $this->check_duplicate( $this->path );
if ( $pass ) {
if( ! is_dir( $user_path ) ) {
@ -410,7 +432,10 @@ class Project extends Common {
if ( ! $this->isAbsPath( $this->path ) ) {
if( ! is_dir( WORKSPACE . '/' . $this->path ) ) {
mkdir( WORKSPACE . '/' . $this->path );
}
} else {
if( ! is_admin() ) {
@ -520,7 +545,7 @@ class Project extends Common {
global $sql;
$query = "DELETE FROM projects WHERE path=?";
$bind_variables = array( $this->path, $_SESSION["user"] );
$bind_variables = array( $this->path );
$return = $sql->query( $query, $bind_variables, 0, "rowCount" );
if( $return > 0 ) {

View file

@ -56,7 +56,12 @@ switch( $_GET['action'] ) {
case 'list':
//Get projects data
if( isset( $_GET["all"] ) ) {
$projects = $Project->get_all_projects();
} else {
$projects = $Project->get_projects();
}
?>
<label><?php i18n("Project List"); ?></label>
<div id="project-list">
@ -72,6 +77,8 @@ switch( $_GET['action'] ) {
<div class="project-wrapper">
<table width="100%" style="word-wrap: break-word;word-break: break-all;">
<?php
if( is_array( $projects ) ) {
foreach( $projects as $project => $data ) {
$show = true;
@ -107,7 +114,7 @@ switch( $_GET['action'] ) {
?>
<td width="70"><a onclick="codiad.message.error(i18n('Active Project Cannot Be Removed'));" class="icon-block bigger-icon"></a></td>
<?php
} elseif( $owner !== $_SESSION["user"] ) {
} elseif( $owner !== $_SESSION["user"] && $owner !== 'nobody' ) {
?>
<td width="70"><a onclick="codiad.message.error(i18n('Projects owned by others can not be deleted'));" class="icon-block bigger-icon"></a></td>
@ -123,6 +130,11 @@ switch( $_GET['action'] ) {
<?php
}
}
} else {
$error = json_decode( $projects, true );
echo $error["message"];
}
?>
</table>
</div>

View file

@ -249,6 +249,12 @@
codiad.modal.load( 500, this.dialog + '?action=list' );
},
list_all: function() {
$( '#modal-content form' ).die( 'submit' ); // Prevent form bubbling
codiad.modal.load( 500, this.dialog + '?action=list&all=true' );
},
/**
* Turn the access array into a table.
*/