Solution

  • Add “Delete any projects without code” permission
  • In drupalorg_node_access(), add check for
    • $op === 'delete'
    • The node is a project in_array($type, project_project_node_types())
    • Use EntityFieldQuery for checking if there is not one versioncontrol_operation entity with repository ID $node->versioncontrol_project['repo']->repo_id.
    • Return NODE_ACCESS_ALLOW if possible.

Deployment

  • Deploy this functionality.
  • Grant “Delete any projects without code” permission to appropriate roles.

Original issue report

I was trying to delete spam-ish projects created from a new user, which were flagged as spam, but I could not even delete them from https://www.drupal.org/user/3611381/admin-content. I selected all the created nodes, and choose Delete item as action, but the projects has not been deleted.

Is it possible to allow site moderators to delete projects when there isn't committed code and there is a single maintainer? This would help to delete spam without requiring an administrator user.
Alternatively, users who aren't confirmed should not be allowed to create projects, especially Drupal core projects as happened in this case. As it is now, a new user can easily get the Git user role and spam the site creating projects.

I am willing to help with code, if this is necessary.

Comments

kiamlaluno created an issue. See original summary.

avpaderno’s picture

Title: Make possible to delete spam projects » Make possible to delete spam projects or not allow not confirmed users to create projects
drumm’s picture

Title: Make possible to delete spam projects or not allow not confirmed users to create projects » Make it possible to delete spam projects
Issue summary: View changes

Yes, we can allow this if there is no code pushed.

I don’t expect we need to disallow deletion if there are co-maintainers added. Although there are valid community projects without code that we do not want accidentally deleted. Maybe a check on if there are issues opened for the project is needed.

We do want to allow new people to show up and be able to contribute right away without barriers. I’ve seen a few cases of people whose first contribution is a project with code. Requiring them to get their account confirmed first discourages people from using Drupal.org for their project.

Added a few implementation notes to the issue summary. For working on this, are your SSH keys at https://www.drupal.org/user/55077/ssh-keys up to date?

avpaderno’s picture

Yes, they are.

drumm’s picture

You should be able to ssh kiamlaluno@wwwdev1.drupalsystems.org now. The dev site for this will be wwwdev1.drupalsystems.org, it should be ready in about 45 minutes. See https://www.drupal.org/drupalorg/docs/build/development-environments/dev... for working with our dev server.

drumm’s picture

Comment notifications do go out - please don’t use webmaster access to delete any comments that aren’t spam or otherwise within policy to delete. It is best to keep the issue comments intact to avoid confusion.

avpaderno’s picture

I apologize. I commented too early, and the comments were useless, as I found out how to proceed.

avpaderno’s picture

Status: Active » Needs review
StatusFileSize
new2.83 KB

I could not verify the code is correct for the query part, as on the test site projects don't have committed code associated. I am not sure the code should call the propertyCondition() method for the repository ID, or fieldCondition().

avpaderno’s picture

The query should verify there is any operation entity, independently from the entity being accessible from the currently logged-in user. (Differently, the code would probably just work for administrator users.)

avpaderno’s picture

I am working on the part about verifying there aren't issues for the project and, eventually, verifying there aren't other maintainers for the project.

avpaderno’s picture

avpaderno’s picture

With the previous patch, the new permission took precedence over the Project module permissions. The patch attached to this comment first checks the Project module allows the user to delete the project; if the user isn't allowed to delete the project, then it checks the user has the delete any project without code permission and there aren't commits nor issues for the project.

I wrote this patch because I noticed there are users with the delete own sandbox project permission, to make the change less disruptive for the current users.

avpaderno’s picture

This is a slightly optimized version of #12. (There a function to check a content type is a project, without verifying the content type name is included in the list of the project types.)

avpaderno’s picture

This is a more generic solution that uses two permissions.
The new permissions are checked after the ones implemented from the Project module, so users with the delete own sandbox project permission can still delete their own projects.

avpaderno’s picture

I found #142957: Prevent project deletion when releases are present, which is someway related. If the Project module would by default not allow to delete project with commits or issues, the patch here would not be anymore necessary. It would be enough to give to the right roles the permission to delete any full project and any sandbox projects.

drumm’s picture

Status: Needs review » Needs work

delete own project without code is not a permission we currently need. People can already delete their own sandbox projects, regardless of other factors. And I think we should leave the restrictions on deleting full projects as-is.

Orphaned issues no longer cause 500 errors, so there isn’t as much of a technical reason to require issues be deleted first. They are still not fun to run into.

avpaderno’s picture

Status: Needs work » Needs review
StatusFileSize
new3.6 KB

Checking for existing issues was added as per suggestion on #3.

The following patch:

  • Allows users with the delete any full project permission to delete full projects they own or full projects created by other users
  • Allows users with the delete any sandbox project permission to delete sandbox projects they own or sandbox projects created by other users
  • Allows users with the delete own full project permission to delete full projects they own
  • Allows users with the delete any sandbox project permission to delete sandbox projects they own or sandbox projects created by other users
  • Allows users with the delete any project without code to delete any project without committed code

The first four points are what the Project module allows.

avpaderno’s picture

I had to re-install Linux, and re-create my SSH keys. The patch in the previous comment is the most recent I created.

avpaderno’s picture

There are more users posting spam or unrelated posts using theme and module projects.

avpaderno’s picture

Issue summary: View changes

I edited the IS to replace webmasters with site moderators.

gisle’s picture

I agree with drumm (#3) that new people to shall be able to contribute right away without barriers (i.e. no role requirement for creating a module or theme project).

Adding an permission that "Allows users with the delete any project without code to delete any project without committed code" should be sufficient permission to allow deletion of spam projects. If it is only given to experienced community members (e.g. site moderators) I don't think there is much of a risk for a site moderator mistaking a community project without code for spam.

The current wave of spam project's are pretty blatent ("Watch XXX for free"), where XXX has nothing to do with Drupal or software.

In the past I've seen some borderline cases, where a community member has created a project page for the sole purpose of linking to a site where one can purchase a "premium" version of the module project. E.g.: https://www.drupal.org/project/autocomplete_labels

We currently have no policy on these, and I would not personally use my site moderator privileges to unpublish or delete this type of code-less projects until we've agreed upon an accepted policy. IMHO, it is not free software, so it shouldn't be on Drupal.org, but these "premium" Drupal projects are far less offensive than the wave of "Watch XXX for free" spam that is currently hitting us.

drumm’s picture

Status: Needs review » Needs work

I was not sure if we needed this, since legitimate project deletions were so rare until the latest spam wave. That seems to be subsiding, but we should be ready for next time.

+  // Avoid project_node_access() is invoked, or it would not permit users with
+  // the "delete any project without code" permission to delete a project that
+  // doesn't have committed code.
+  if ($hook === 'node_access') {
+    unset($implementations['project']);
+  }

Overriding & re-creating this will be harder to maintain and work on in the future. What we can do is:

  • Grant site moderators the delete any full project permission and any other node module permissions needed for deletion.
  • The change from this issue should return NODE_ACCESS_DENY if a project has code, so it overrides other access rules. No additional permission definition necessary, as admins have bypass node access.
avpaderno’s picture

Status: Needs work » Needs review
StatusFileSize
new942 bytes

  • drumm committed 52816be on 7.x-3.x
    Issue #3046921 by apaderno, drumm, gisle: Make it possible to delete...

  • drumm committed fc8acc8 on 7.x-3.x
    Issue #3046921 by apaderno, drumm, gisle: Make it possible to delete...
drumm’s picture

Status: Needs review » Fixed

Thanks, this is deployed now.

As we move toward more reliance on GitLab, we likely won’t be maintaining the versioncontrol* data in the local DB in the future. I replaced the check with an API call. Since that API call is an HTTP request, I’ve added a few more conditions for checking, to minimize the relatively-slow requests.

Sandbox project authors can delete their sandbox project at any time. I'm allowing deleting any sandbox project, regardless of code.

gisle’s picture

Status: Fixed » Active
StatusFileSize
new9.93 KB

Still not possible for a site moderator to delete spam projects.

I unpublished this project this morning:
https://www.drupal.org/project/venom2lettherebecarnage2021movieaustralia...

However, I am not able to delete it.

Screenshot

There is no "delete" link in the "Operations" column, like it is for other nodes.

There is a "Delete item" in the "Operations" pull-down menu, but selecting it and pressing "Execute" followed by "Confirm" makes the progress indicator appear, but no item is deleted.

avpaderno’s picture

I have deleted spam projects since this issue has been marked fixed; I deleted the last one 10 minutes ago. I always see the delete link for each created projects.

gisle’s picture

apaderno,
my role here is 'site moderator'. Was the permission to delete projects added to that role, or some other elevated role? (I belive you have several.)

avpaderno’s picture

@gisle Commit fc8acc8 gave the delete any full project and delete any sandbox project permissions to site moderators. The difference between what you see and what I see could be caused by other permissions you don't have, but there should be code that check those permissions (and I don't know which module could interfere).

avpaderno’s picture

I can confirm you are listed between the users with both those permissions.

Thinking more, the issue could be in the settings for the /user/[uid]/admin-content view.

drumm’s picture

Assigned: Unassigned » drumm

The difference is the administer projects permission. This grants some blanket allow access to projects. In absence of that, nothing is allowing or denying delete access to projects for site moderators, so it defaults to deny.

We should be able to grant some specific delete permissions to make this work.

  • drumm committed 79c032f on 7.x-3.x
    Issue #3046921: Explicitly allow site moderators to delete projects,...
drumm’s picture

Status: Active » Fixed

This should be good now.

Please remember - this is only for deleting spam and test content, and anything else specifically against policies. Other cleanups and handling requests from maintainers should still be escalated to the infrastructure issue queue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.