Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
feeds
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
feeds
Commits
e280ce25
Commit
e280ce25
authored
8 years ago
by
megachriz
Committed by
MegaChriz
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue #2485059 by MegaChriz: Added delete protection for user id 1.
parent
ea2c278f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/FeedsUserProcessor.inc
+22
-0
22 additions, 0 deletions
plugins/FeedsUserProcessor.inc
tests/feeds_processor_user.test
+81
-0
81 additions, 0 deletions
tests/feeds_processor_user.test
with
103 additions
and
0 deletions
plugins/FeedsUserProcessor.inc
+
22
−
0
View file @
e280ce25
...
@@ -179,6 +179,16 @@ class FeedsUserProcessor extends FeedsProcessor {
...
@@ -179,6 +179,16 @@ class FeedsUserProcessor extends FeedsProcessor {
* Delete multiple user accounts.
* Delete multiple user accounts.
*/
*/
protected
function
entityDeleteMultiple
(
$uids
)
{
protected
function
entityDeleteMultiple
(
$uids
)
{
// Prevent user 1 from being deleted.
if
(
in_array
(
1
,
$uids
))
{
$uids
=
array_diff
(
$uids
,
array
(
1
));
// But do delete the associated feeds item.
db_delete
(
'feeds_item'
)
->
condition
(
'entity_type'
,
$this
->
entityType
())
->
condition
(
'entity_id'
,
1
)
->
execute
();
}
user_delete_multiple
(
$uids
);
user_delete_multiple
(
$uids
);
}
}
...
@@ -378,6 +388,18 @@ class FeedsUserProcessor extends FeedsProcessor {
...
@@ -378,6 +388,18 @@ class FeedsUserProcessor extends FeedsProcessor {
return
0
;
return
0
;
}
}
/**
* Overrides FeedsProcessor::initEntitiesToBeRemoved().
*
* Removes user 1 from the list of entities to be removed.
*/
protected
function
initEntitiesToBeRemoved
(
FeedsSource
$source
,
FeedsState
$state
)
{
parent
::
initEntitiesToBeRemoved
(
$source
,
$state
);
// Prevent user 1 from being deleted.
unset
(
$state
->
removeList
[
1
]);
}
/**
/**
* Overrides FeedsProcessor::clean().
* Overrides FeedsProcessor::clean().
*
*
...
...
This diff is collapsed.
Click to expand it.
tests/feeds_processor_user.test
+
81
−
0
View file @
e280ce25
...
@@ -916,6 +916,87 @@ class FeedsCSVtoUsersTest extends FeedsWebTestCase {
...
@@ -916,6 +916,87 @@ class FeedsCSVtoUsersTest extends FeedsWebTestCase {
$this
->
assertText
(
"Failed importing 'Gomez'. User's timezone is not valid."
);
$this
->
assertText
(
"Failed importing 'Gomez'. User's timezone is not valid."
);
}
}
/**
* Tests if user 1 cannot be deleted using the delete non-existing feature.
*/
public
function
testUser1ProtectionWhenDeletingNonExistent
()
{
// Set to delete non-existing users.
$this
->
setSettings
(
'user_import'
,
'FeedsFileFetcher'
,
array
());
$this
->
setSettings
(
'user_import'
,
'FeedsUserProcessor'
,
array
(
'update_existing'
=>
FEEDS_UPDATE_EXISTING
,
'update_non_existent'
=>
'delete'
,
));
// Set mail address of user 1 to "fester@example.com". An user with this
// mail address is missing in the feed later.
$account
=
user_load
(
1
);
$edit
[
'mail'
]
=
'fester@example.com'
;
user_save
(
$account
,
$edit
);
// Import the first file, which contains the mail address of user 1.
$this
->
importFile
(
'user_import'
,
$this
->
absolutePath
()
.
'/tests/feeds/users.csv'
);
$this
->
assertText
(
'Updated 1 user'
);
// Ensure the username of user 1 was updated.
$account
=
user_load
(
1
,
TRUE
);
$this
->
assertEqual
(
'Fester'
,
$account
->
name
);
// Now import the second file, where the mail address of user 1 is missing.
$this
->
importFile
(
'user_import'
,
$this
->
absolutePath
()
.
'/tests/feeds/users2.csv'
);
$this
->
assertNoText
(
'Removed 1 user'
);
// Ensure that user 1 still exists.
$account
=
db_select
(
'users'
)
->
fields
(
'users'
)
->
condition
(
'uid'
,
1
)
->
execute
()
->
fetch
();
$this
->
assertTrue
(
is_object
(
$account
),
'User 1 still exists.'
);
}
/**
* Tests if user 1 cannot be deleted using the delete form.
*/
public
function
testUser1ProtectionWhenDeletingAll
()
{
// Set to update existing users.
$this
->
setSettings
(
'user_import'
,
'FeedsFileFetcher'
,
array
());
$this
->
setSettings
(
'user_import'
,
'FeedsUserProcessor'
,
array
(
'update_existing'
=>
FEEDS_UPDATE_EXISTING
,
));
// Set mail address of user 1 to "fester@example.com".
$account
=
user_load
(
1
);
$edit
[
'mail'
]
=
'fester@example.com'
;
user_save
(
$account
,
$edit
);
// Import a file that contains the mail address of user 1.
$this
->
importFile
(
'user_import'
,
$this
->
absolutePath
()
.
'/tests/feeds/users.csv'
);
$this
->
assertText
(
'Updated 1 user'
);
// Ensure the username of user 1 was updated.
$account
=
user_load
(
1
,
TRUE
);
$this
->
assertEqual
(
'Fester'
,
$account
->
name
);
// Now delete all items. User 1 should not be deleted.
$this
->
drupalPost
(
'import/user_import/delete-items'
,
array
(),
'Delete'
);
// Ensure that user 1 still exists.
$account
=
db_select
(
'users'
)
->
fields
(
'users'
)
->
condition
(
'uid'
,
1
)
->
execute
()
->
fetch
();
$this
->
assertTrue
(
is_object
(
$account
),
'User 1 still exists.'
);
// But ensure that the associated feeds item did got deleted.
$count
=
db_select
(
'feeds_item'
)
->
fields
(
'feeds_item'
)
->
condition
(
'entity_type'
,
'user'
)
->
condition
(
'entity_id'
,
1
)
->
countQuery
()
->
execute
()
->
fetchField
();
$this
->
assertEqual
(
0
,
$count
,
'The feeds item for user 1 was deleted.'
);
}
/**
/**
* Log in an imported user.
* Log in an imported user.
*
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment