mirror of
https://github.com/xevidos/codiad.git
synced 2024-11-10 21:26:35 +01:00
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:
parent
4dab45e0e7
commit
0dedba59d2
@ -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] ) {
|
||||
|
||||
$pass = true;
|
||||
}
|
||||
return( $pass );
|
||||
echo var_dump( $level, $user_level, $path );
|
||||
|
||||
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;
|
||||
|
@ -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 ) ) {
|
||||
|
||||
$user_path = WORKSPACE . '/' . preg_replace( '/[^\w-]/', '', strtolower( $_SESSION["user"] ) );
|
||||
$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 ) ) {
|
||||
|
||||
mkdir( WORKSPACE . '/' . $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 ) {
|
||||
|
@ -56,7 +56,12 @@ switch( $_GET['action'] ) {
|
||||
case 'list':
|
||||
|
||||
//Get projects data
|
||||
$projects = $Project->get_projects();
|
||||
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,56 +77,63 @@ switch( $_GET['action'] ) {
|
||||
<div class="project-wrapper">
|
||||
<table width="100%" style="word-wrap: break-word;word-break: break-all;">
|
||||
<?php
|
||||
foreach( $projects as $project => $data ) {
|
||||
if( is_array( $projects ) ) {
|
||||
|
||||
$show = true;
|
||||
if( $show ) {
|
||||
foreach( $projects as $project => $data ) {
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td width="70"><a onclick="codiad.project.open('<?php echo( $data['path'] );?>');" class="icon-folder bigger-icon"></a></td>
|
||||
<td width="150"><?php echo($data['name']);?></td>
|
||||
<td width="250"><?php echo($data['path']);?></td>
|
||||
<?php
|
||||
$owner = $Project->get_owner( $data['path'] );
|
||||
if( $owner == 'nobody' ) {
|
||||
|
||||
?>
|
||||
<td width="70"><a onclick="codiad.message.error(i18n('Public projects can not be managed'));" class="icon-block bigger-icon"></a></td>
|
||||
<?php
|
||||
} elseif( $owner !== $_SESSION["user"] ) {
|
||||
|
||||
?>
|
||||
<td width="70"><a onclick="codiad.message.error(i18n('Projects owned by others can not be managed'));" class="icon-block bigger-icon"></a></td>
|
||||
<?php
|
||||
} else {
|
||||
|
||||
?>
|
||||
<td width="70"><a onclick="codiad.project.manage_access( '<?php echo( $data['path'] );?>' );" class="icon-lock bigger-icon"></a></td>
|
||||
<?php
|
||||
}
|
||||
$show = true;
|
||||
if( $show ) {
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td width="70"><a onclick="codiad.project.open('<?php echo( $data['path'] );?>');" class="icon-folder bigger-icon"></a></td>
|
||||
<td width="150"><?php echo($data['name']);?></td>
|
||||
<td width="250"><?php echo($data['path']);?></td>
|
||||
<?php
|
||||
$owner = $Project->get_owner( $data['path'] );
|
||||
if( $owner == 'nobody' ) {
|
||||
|
||||
?>
|
||||
<td width="70"><a onclick="codiad.message.error(i18n('Public projects can not be managed'));" class="icon-block bigger-icon"></a></td>
|
||||
<?php
|
||||
} elseif( $owner !== $_SESSION["user"] ) {
|
||||
|
||||
?>
|
||||
<td width="70"><a onclick="codiad.message.error(i18n('Projects owned by others can not be managed'));" class="icon-block bigger-icon"></a></td>
|
||||
<?php
|
||||
} else {
|
||||
|
||||
?>
|
||||
<td width="70"><a onclick="codiad.project.manage_access( '<?php echo( $data['path'] );?>' );" class="icon-lock bigger-icon"></a></td>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
if( $_SESSION['project'] == $data['path'] ) {
|
||||
|
||||
?>
|
||||
<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"] && $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>
|
||||
<?php
|
||||
} else {
|
||||
|
||||
?>
|
||||
<td width="70"><a onclick="codiad.project.delete('<?php echo($data['name']);?>','<?php echo($data['path']);?>');" class="icon-cancel-circled bigger-icon"></a></td>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tr>
|
||||
<?php
|
||||
if( $_SESSION['project'] == $data['path'] ) {
|
||||
|
||||
?>
|
||||
<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"] ) {
|
||||
|
||||
?>
|
||||
<td width="70"><a onclick="codiad.message.error(i18n('Projects owned by others can not be deleted'));" class="icon-block bigger-icon"></a></td>
|
||||
<?php
|
||||
} else {
|
||||
|
||||
?>
|
||||
<td width="70"><a onclick="codiad.project.delete('<?php echo($data['name']);?>','<?php echo($data['path']);?>');" class="icon-cancel-circled bigger-icon"></a></td>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
$error = json_decode( $projects, true );
|
||||
echo $error["message"];
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
|
@ -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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user