this has been a long-standing problem, but seems to take a slightly different form in 5.x-2.x:
the comment is created, but it wipes out all the current issue's metadata (the values stored in {project_issues})
in these cases, we need to temporarily impersonate a user that has the proper perms. drupal provides a safe mechanism now to accomplish this:
session_save_session(FALSE);
global $user;
// Do unspeakable deeds to $user.
// When done, set $user back and:
session_save_session(TRUE);
we also need to decide if we're going to provide a setting for the user to use, or simply use uid 1 and submit the comment as owned by uid 0 anyways.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | auto_close_fix.patch | 10.49 KB | hunmonk |
| #5 | auto_close_fix.patch | 4.56 KB | micahw156 |
| #1 | auto_close_fix.patch | 4.45 KB | hunmonk |
Comments
Comment #1
hunmonk commenteduser_access('access project issues', $account)the exact right check that we want?Comment #2
micahw156I had to work hard to break this one, but I found a way. Two ways, actually.
project_issue_auto_close_user, the original flaw still exists, because theauto_close_useris still anonymous.I tried to rewrite a new patch for this, but wasn't quite sure how to do it. I think all it really needs is another call to
user_access('access project issues', $user)as part of the safety check in theproject_issue_auto_closefunction, probably with an appropriate watchdog error on failure.Comment #3
dww@micah: thanks for testing this. i think your proposal to do a safety check in project_issue_auto_close() sounds reasonable. feel free to take a stab at coding it, since that seems like the right approach to addressing the concerns you raised. thanks!
Comment #4
dwwoh, and while you're re-rolling this, the following is wrong:
t('The anonymous user'). There's a setting for this -- that should be:variable_get('anonymous', t('Anonymous')).otherwise, a quick visual skim of the patch seems ok. i'll study more closely once it's been rerolled to handle this extra safety check.
thanks!
-derek
Comment #5
micahw156I updated the patch and tested as many possible scenarios I could think of. Please review.
Comment #6
dwwUpon slightly closer inspection, this looks pretty good. A few concerns:
A) This is a bad idea inside a call to t():
<em><none></em>. If we're hard-coding<none>in the rest of this patch, untranslated, we don't want to expose this to translators or they're likely to try to translate it, which would lead to much confusion and trouble. So, we want to force this little chunk to be untranslatable by putting it in a placeholder, outside of the t() string itself. Furthermore, we want to use theme('placeholder') (by means of % in the t() string) to ensure things are consistently themed on sites that choose to use something other than<em>to indicate placeholders in help text. So, this line should be:B) I must admit it's a little counter intuitive that the value of this setting is either empty for anonymous,
<none>for disabled, and a regular name for a regular user. Why not just use empty for none,variable_get('anonymous', t('Anonymous'))for anonymous, and a regular name for regular users? Then, we don't even need to mess with this<none>business from (A). Maybe hunmonk has a good reason? Is it just thatvariable_get('anonymous', t('Anonymous'))isn't foolproof, and someone really could register a user called "anonymous"?C) In your new safety code, if the call to user_load() fails, you still need to set session_save_session(TRUE) before you return or all hell could break loose for anything else happening in hook_cron().
Comment #7
micahw156Oh, yes. I just realized that the code to user_load for the anonymous user is probably unnecessary,
Because $user would already be set to the anonymous user, or it could even be set to a regular user who fired cron manually. So clearly those three lines should come back out. I muddled this up a bit once I realized why my test for user_access was failing when it was inside the
if($name)conditional.Although using
<none>is somewhat consistent with other things in core, (such as using<front>to indicate the front page,) dww raises some good usability points in A and B. It would also make things to that auto close is disabled unless the administrator chooses to configure it. It's tempting to go so far as to say that this needs to be set to a real user to be enabled, even if uid=0 has sufficient privileges to do this.When I first started using project*, I didn't know about the auto closer. The first time I had a "fixed" issue switch to "closed" by anonymous was very disconcerting, because I don't even let anonymous access content - let alone projects - on that site. I like the idea that this value has to be configured to be enabled, if only because it forces the site admin to be aware of it happening.
OTOH, if it's more practical to allow anonymous to do this for sites that want it, then if some user also registers "anonymous" it's unlikely that the admin would specify this user as the auto close user. In that case, something like this would probably work:
Otherwise, the second test could just exit if
$name == variable_get('anonymous', t('Anonymous')).What do you think?
Comment #8
hunmonk commentedi believe this addresses all issues, and some others i found along the way:
not quite. what we need to do is
since we already do all three of these steps at the bottom of the function, i simply made the actual auto-closing code conditional upon the safety checks being passed.
ifchecks fail b/c uid = 0)Comment #9
micahw156There's still a small problem with blank vs anonymous user that I couldn't quite sort out.
When the Anonymous user is selected (i.e.:
project_issue_auto_close_userinvariablesis set tos:1:"0";), then the prompting field in admin/project/project-issue-settings appears blank, and I'm pretty sure the cron job is treating this as unset, as well.I tried tweaking the patch, but only managed to get it stuck in the other direction, with it using the Anonymous user, even when it should have been blank to not run.
Comment #10
hunmonk commentedi don't know what you're talking about. here's what i get when the auto-close user is set to anon:
which is exactly as it should be. perhaps you need to clear your variable cache??
Comment #11
micahw156Oops. Faulty test procedures on my side.
Yes, everything now works as expected.
Comment #12
dwwVisual inspection looks good. micah and hunmonk say it works. RTBC. ;)
Comment #13
hunmonk commentedcommitted to 5.x-2.x. setting back to active, as this still needs to be deployed on d.o, and sec.d.o
Comment #14
dwwI'll deal with deployment.
Comment #15
dwwoh, whoops. this was deployed a while ago, i just forgot about closing this issue...
Comment #16
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.