Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Needham <needham.thomas@gmail.com>2012-06-16 03:14:40 +0400
committerTom Needham <needham.thomas@gmail.com>2012-06-16 03:14:40 +0400
commite37ef6dd473eaedcdf2814445ae12fb39786d585 (patch)
tree7513cfb664c4b32061b78b53cb11c71b73515568 /lib/migrate.php
parent03951ccc6b4d710e2e21d4344842a7c310453871 (diff)
Move user import to personal settings. Fix user migration between servers.
Diffstat (limited to 'lib/migrate.php')
-rw-r--r--lib/migrate.php40
1 files changed, 14 insertions, 26 deletions
diff --git a/lib/migrate.php b/lib/migrate.php
index f9cab915d04..5939ba32e50 100644
--- a/lib/migrate.php
+++ b/lib/migrate.php
@@ -196,7 +196,7 @@ class OC_Migrate{
* @param optional $uid userid of new user
*/
public static function import( $path, $type='user', $uid=null ){
- OC_Util::checkAdminUser();
+
$datadir = OC_Config::getValue( 'datadirectory' );
// Extract the zip
if( !$extractpath = self::extractZip( $path ) ){
@@ -216,12 +216,19 @@ class OC_Migrate{
}
self::$exporttype = $type;
+ $currentuser = OC_User::getUser();
+
// Have we got a user if type is user
if( self::$exporttype == 'user' ){
- if( !$uid ){
- self::$uid = $json->exporteduser;
- } else {
- self::$uid = $uid;
+ self::$uid = !is_null($uid) ? $uid : $currentuser;
+ }
+
+ // We need to be an admin if we are not importing our own data
+ if(($type == 'user' && self::$uid != $currentuser) || $type != 'user' ){
+ if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )){
+ // Naughty.
+ OC_Log::write( 'migration', 'Import not permitted.', OC_Log::ERROR );
+ return json_encode( array( 'success' => false ) );
}
}
@@ -229,27 +236,8 @@ class OC_Migrate{
switch( self::$exporttype ){
case 'user':
// Check user availability
- if( OC_User::userExists( self::$uid ) ){
- OC_Log::write( 'migration', 'User already exists', OC_Log::ERROR );
- return json_encode( array( 'success' => false ) );
- }
- $run = true;
- OC_Hook::emit( "OC_User", "pre_createUser", array( "run" => &$run, "uid" => self::$uid, "password" => $json->hash ));
- if( !$run ){
- // Something stopped the user creation
- OC_Log::write( 'migration', 'User creation failed', OC_Log::ERROR );
- return json_encode( array( 'success' => false ) );
- }
- // Create the user
- if( !self::createUser( self::$uid, $json->hash ) ){
- return json_encode( array( 'success' => false ) );
- }
- // Emit the post_createUser hook (password is already hashed, will cause problems
- OC_Hook::emit( "OC_User", "post_createUser", array( "uid" => self::$uid, "password" => $json->hash ));
- // Make the new users data dir
- $path = $datadir . '/' . self::$uid;
- if( !mkdir( $path, 0755, true ) ){
- OC_Log::write( 'migration', 'Failed to create users data dir: '.$path, OC_Log::ERROR );
+ if( !OC_User::userExists( self::$uid ) ){
+ OC_Log::write( 'migration', 'User doesn\'t exist', OC_Log::ERROR );
return json_encode( array( 'success' => false ) );
}
// Copy data