Merge branch 'refactoring' of git.kde.org:owncloud into refactoring

This commit is contained in:
Frank Karlitschek 2011-04-17 01:13:07 +02:00
commit 85a6097c03
14 changed files with 181 additions and 54 deletions

View File

@ -12,23 +12,14 @@ if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin'
exit(); exit();
} }
$groups = array(); $name = $_POST["groupname"];
if( isset( $_POST["groups"] )){
$groups = $_POST["groups"];
}
$username = $_POST["username"];
$password = $_POST["password"];
foreach( $groups as $i ){
OC_GROUP::addToGroup( $username, $i );
}
// Return Success story // Return Success story
if( OC_USER::createUser( $username, $password )){ if( OC_GROUP::createGroup( $name )){
echo json_encode( array( "status" => "success", "data" => array( "username" => $username, "groups" => implode( ", ", $groups )))); echo json_encode( array( "status" => "success", "data" => array( "groupname" => $name )));
} }
else{ else{
echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to add user" ))); echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to add group" )));
} }
?> ?>

View File

@ -19,12 +19,11 @@ if( isset( $_POST["groups"] )){
$username = $_POST["username"]; $username = $_POST["username"];
$password = $_POST["password"]; $password = $_POST["password"];
foreach( $groups as $i ){
OC_GROUP::addToGroup( $username, $i );
}
// Return Success story // Return Success story
if( OC_USER::createUser( $username, $password )){ if( OC_USER::createUser( $username, $password )){
foreach( $groups as $i ){
OC_GROUP::addToGroup( $username, $i );
}
echo json_encode( array( "status" => "success", "data" => array( "username" => $username, "groups" => implode( ", ", $groups )))); echo json_encode( array( "status" => "success", "data" => array( "username" => $username, "groups" => implode( ", ", $groups ))));
} }
else{ else{

View File

@ -0,0 +1,25 @@
<?php
// Init owncloud
require_once('../../lib/base.php');
// We send json data
header( "Content-Type: application/jsonrequest" );
// Check if we are a user
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){
echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
exit();
}
$name = $_POST["groupname"];
// Return Success story
if( OC_GROUP::deleteGroup( $name )){
echo json_encode( array( "status" => "success", "data" => array( "groupname" => $name )));
}
else{
echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to delete group" )));
}
?>

25
admin/ajax/removeuser.php Normal file
View File

@ -0,0 +1,25 @@
<?php
// Init owncloud
require_once('../../lib/base.php');
// We send json data
header( "Content-Type: application/jsonrequest" );
// Check if we are a user
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){
echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
exit();
}
$name = $_POST["username"];
// Return Success story
if( OC_USER::deleteUser( $name )){
echo json_encode( array( "status" => "success", "data" => array( "username" => $name )));
}
else{
echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to delete user" )));
}
?>

View File

@ -12,10 +12,15 @@ $(document).ready(function(){
"Create an account": function() { "Create an account": function() {
var post = $( "#createuserdata" ).serialize(); var post = $( "#createuserdata" ).serialize();
$.post( 'ajax/createuser.php', post, function(data){ $.post( 'ajax/createuser.php', post, function(data){
var newrow = '<tr><td>' + data.data.username + '</td>'; if( data.status == "success" ){
newrow = newrow + '<td>' + data.data.groups + '</td>'; var newrow = '<tr><td>' + data.data.username + '</td>';
newrow = newrow + '<td><a href="" class="edituser-button">edit</a> | <a class="removeuser-button" href="">remove</a></td></tr>'; newrow = newrow + '<td>' + data.data.groups + '</td>';
$("#userstable").append( newrow ); newrow = newrow + '<td><a href="" class="edituser-button">edit</a> | <a class="removeuser-button" href="">remove</a></td></tr>';
$("#userstable").append( newrow );
}
else{
alert( "Bug By Jakob (c)" );
}
}); });
$( this ).dialog( "close" ); $( this ).dialog( "close" );
}, },
@ -61,7 +66,7 @@ $(document).ready(function(){
return false; return false;
}); });
// Dialog for adding users // Removing users
$( "#removeuser-form" ).dialog({ $( "#removeuser-form" ).dialog({
autoOpen: false, autoOpen: false,
height: 300, height: 300,
@ -69,6 +74,15 @@ $(document).ready(function(){
modal: true, modal: true,
buttons: { buttons: {
"Remove user": function() { "Remove user": function() {
var post = $( "#removeuserdata" ).serialize();
$.post( 'ajax/removeuser.php', post, function(data){
if( data.status == "success" ){
$( "a[x-uid='"+uid+"']" ).parent().remove();
}
else{
alert( "Bug By Jakob (c)" );
}
});
$( this ).dialog( "close" ); $( this ).dialog( "close" );
}, },
Cancel: function() { Cancel: function() {
@ -76,7 +90,7 @@ $(document).ready(function(){
} }
}, },
close: function() { close: function() {
allFields.val( "" ).removeClass( "ui-state-error" ); true;
} }
}); });
@ -84,10 +98,28 @@ $(document).ready(function(){
.click(function() { .click(function() {
uid = $( this ).parent().attr( 'x-uid' ); uid = $( this ).parent().attr( 'x-uid' );
$("#deleteuserusername").html(uid); $("#deleteuserusername").html(uid);
$("#deleteusernamefield").val(uid);
$( "#removeuser-form" ).dialog( "open" ); $( "#removeuser-form" ).dialog( "open" );
return false; return false;
}); });
// Add a group
$( "#creategroupbutton" )
.click(function(){
var post = $( "#creategroupdata" ).serialize();
$.post( 'ajax/creategroup.php', post, function(data){
if( data.status == "success" ){
var newrow = '<tr><td>' + data.data.groupname + '</td>';
newrow = newrow + '<td><a class="removegroup-button" href="">remove</a></td></tr>';
$("#groupstable").append( newrow );
}
else{
alert( "something went wrong! sorry!" );
}
});
return false;
});
// Dialog for adding users // Dialog for adding users
$( "#removegroup-form" ).dialog({ $( "#removegroup-form" ).dialog({
autoOpen: false, autoOpen: false,
@ -96,9 +128,14 @@ $(document).ready(function(){
modal: true, modal: true,
buttons: { buttons: {
"Remove group": function(){ "Remove group": function(){
var post = $( "#deletegroupdata" ).serialize(); var post = $( "#removegroupdata" ).serialize();
$.post( 'ajax/deletegroup.php', post, function(data){ $.post( 'ajax/removegroup.php', post, function(data){
$( "a[x-gid='"+gid+"']" ).parent().remove(); if( data.status == "success" ){
$( "a[x-gid='"+gid+"']" ).parent().remove();
}
else{
alert( "Bug By Jakob (c)" );
}
}); });
$( this ).dialog( "close" ); $( this ).dialog( "close" );
}, },
@ -107,7 +144,7 @@ $(document).ready(function(){
} }
}, },
close: function(){ close: function(){
allFields.val( "" ).removeClass( "ui-state-error" ); true;
} }
}); });

View File

@ -28,7 +28,7 @@
<a id="adduser-button" href="">New user</a> <a id="adduser-button" href="">New user</a>
<h2>Groups</h2> <h2>Groups</h2>
<form> <form id="creategroupdata">
<table id="groupstable"> <table id="groupstable">
<thead> <thead>
<tr> <tr>
@ -36,6 +36,12 @@
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
<tfoot>
<tr>
<td><input type="text" name="groupname" id="creategroupname" /></td>
<td><button id="creategroupbutton">Create group</button></td>
</tr>
</tfoot>
<tbody> <tbody>
<?php foreach($_["groups"] as $group): ?> <?php foreach($_["groups"] as $group): ?>
<tr> <tr>
@ -43,17 +49,10 @@
<td x-gid="<?php echo $group["name"]; ?>"><a class="removegroup-button" href="">remove</a></td> <td x-gid="<?php echo $group["name"]; ?>"><a class="removegroup-button" href="">remove</a></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<tr>
<td><input type="text" name="name" /></td>
<td><input type="submit" /></td>
</tr>
</tbody> </tbody>
</table> </table>
</form> </form>
<a id="addgroup-button" href="">Add group</a>
<div id="adduser-form" title="Add user"> <div id="adduser-form" title="Add user">
<form id="createuserdata"> <form id="createuserdata">
<fieldset> <fieldset>
@ -82,13 +81,13 @@
<div id="removeuser-form" title="Remove user"> <div id="removeuser-form" title="Remove user">
<form id="removeuserdata"> <form id="removeuserdata">
Do you really want to delete user <span id="deleteuserusername">$user</span>? Do you really want to delete user <span id="deleteuserusername">$user</span>?
<input type="hidden" name="username" value=""> <input id="deleteusernamefield" type="hidden" name="username" value="">
</form> </form>
</div> </div>
<div id="removegroup-form" title="Remove Group"> <div id="removegroup-form" title="Remove Group">
<form id="removeuserdata"> <form id="removegroupdata">
Do you really want to delete group <span id="deletegroupgroupname">$group</span>? Do you really want to delete group <span id="deletegroupgroupname">$group</span>?
<input id="deletegroupnamefield" type="hidden" name="username" value=""> <input id="deletegroupnamefield" type="hidden" name="groupname" value="">
</form> </form>
</div> </div>

View File

@ -35,6 +35,13 @@ abstract class OC_GROUP_BACKEND {
*/ */
public static function createGroup($groupName){} public static function createGroup($groupName){}
/**
* Try to delete Group
*
* @param string $groupName The name of the group to delete
*/
public static function deleteGroup($groupName){}
/** /**
* Check if a user belongs to a group * Check if a user belongs to a group
* *

View File

@ -66,6 +66,18 @@ class OC_GROUP_DATABASE extends OC_GROUP_BACKEND {
} }
} }
/**
* Try to delete a group
*
* @param string $groupName The name of the group to delete
*/
public static function deleteGroup( $gid ){
$query = OC_DB::prepare( "DELETE FROM `*PREFIX*groups` WHERE `gid` = ?" );
$result = $query->execute( array( $gid ));
return true;
}
/** /**
* Check if a user belongs to a group * Check if a user belongs to a group
* *

View File

@ -37,6 +37,12 @@ abstract class OC_USER_BACKEND {
*/ */
public static function createUser($username, $password){} public static function createUser($username, $password){}
/**
* @brief Delete a new user
* @param $username The username of the user to delete
*/
public static function deleteUser( $username ){}
/** /**
* Try to login a user * Try to login a user
* *

View File

@ -64,6 +64,18 @@ class OC_USER_DATABASE extends OC_USER_BACKEND {
} }
} }
/**
* Try to delete a user
*
* @param string $username The username of the user to delete
*/
public static function deleteUser( $uid ){
$query = OC_DB::prepare( "DELETE FROM `*PREFIX*users` WHERE `uid` = ?" );
$result = $query->execute( array( $uid ));
return true;
}
/** /**
* Try to login a user * Try to login a user
* *

View File

@ -318,7 +318,6 @@ class OC_APP{
* -# unzipping it * -# unzipping it
* -# including appinfo/installer.php * -# including appinfo/installer.php
* -# executing "oc_app_install()" * -# executing "oc_app_install()"
* -# renaming appinfo/app.sample.php to appinfo/app.php
* *
* It is the task of oc_app_install to create the tables and do whatever is * It is the task of oc_app_install to create the tables and do whatever is
* needed to get the app working. * needed to get the app working.
@ -346,8 +345,6 @@ class OC_APP{
* - pretend: boolean, if set true the system won't do anything * - pretend: boolean, if set true the system won't do anything
* - noupgrade: boolean, if true the function oc_app_upgrade will be * - noupgrade: boolean, if true the function oc_app_upgrade will be
* skipped * skipped
* - keepappinfo: boolean. If set true, the folder appinfo will not be
* deleted, appinfo/app.php will not be replaced by a new version
* *
* This function works as follows * This function works as follows
* -# fetching the file * -# fetching the file
@ -355,7 +352,6 @@ class OC_APP{
* -# unzipping new file * -# unzipping new file
* -# including appinfo/installer.php * -# including appinfo/installer.php
* -# executing "oc_app_upgrade( $options )" * -# executing "oc_app_upgrade( $options )"
* -# renaming appinfo/app.sample.php to appinfo/app.php
*/ */
public static function upgradeApp( $data = array()){ public static function upgradeApp( $data = array()){
// TODO: write function // TODO: write function

View File

@ -378,6 +378,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
} }
public function fromTmpFile($tmpFile,$path){ public function fromTmpFile($tmpFile,$path){
die( "oh nooo!" );
$fileStats = stat($tmpFile); $fileStats = stat($tmpFile);
if(rename($tmpFile,$this->datadir.$path)){ if(rename($tmpFile,$this->datadir.$path)){
touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']); touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']);
@ -447,7 +448,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
} }
return $return; return $return;
} }
/** /**
* @brief get the size of folder and it's content * @brief get the size of folder and it's content
* @param string $path file path * @param string $path file path
@ -462,7 +463,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
return $this->calculateFolderSize($path); return $this->calculateFolderSize($path);
} }
} }
/** /**
* @brief calulate the size of folder and it's content and cache it * @brief calulate the size of folder and it's content and cache it
* @param string $path file path * @param string $path file path
@ -493,7 +494,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
} }
return $size; return $size;
} }
/** /**
* @brief clear the folder size cache of folders containing a file * @brief clear the folder size cache of folders containing a file
* @param string $path * @param string $path

View File

@ -78,6 +78,24 @@ class OC_GROUP {
} }
} }
/**
* Try to create a new group
*
* @param string $groupName The name of the group to create
*/
public static function createGroup($gid) {
return self::$_backend->createGroup($gid);
}
/**
* Try to delete Group
*
* @param string $groupName The name of the group to delete
*/
public static function deleteGroup($gid) {
return self::$_backend->deleteGroup($gid);
}
/** /**
* Check if a user belongs to a group * Check if a user belongs to a group
* *
@ -124,13 +142,4 @@ class OC_GROUP {
public static function getGroups() { public static function getGroups() {
return self::$_backend->getGroups(); return self::$_backend->getGroups();
} }
/**
* create a new group
*
* @param string $name Name of the group
*/
public static function createGroup($name) {
return self::$_backend->createGroup($name);
}
} }

View File

@ -95,6 +95,14 @@ class OC_USER {
return self::$_backend->createUser( $username, $password ); return self::$_backend->createUser( $username, $password );
} }
/**
* @brief Delete a new user
* @param $username The username of the user to delete
*/
public static function deleteUser( $username ){
return self::$_backend->deleteUser( $username );
}
/** /**
* @brief try to login a user * @brief try to login a user
* @param $username The username of the user to log in * @param $username The username of the user to log in