Modify ↓
#12924 closed defect (fixed)
BlogDraftPlugin fails to save if author doesn't fit username
Reported by: | Owned by: | osimons | |
---|---|---|---|
Priority: | low | Component: | FullBlogPlugin |
Severity: | minor | Keywords: | blog draft |
Cc: | Trac Release: | 1.0 |
Description
In the case that username doesn't fit author, the draft post can not be saved.
For example, if the username is bitelxux and the author is Bitelxux it will not be saved.
Should it be an acceptable fix to compare "lower" values ?
-
fullblogplugin/0.11/sample-plugins/BlogDraftPlugin.py
old new 51 51 if resource.realm == 'blog' and resource.id: 52 52 the_post = BlogPost(self.env, resource.id, resource.version) 53 53 for category in the_post.category_list: 54 if category in self.draft and the_post.author != username:54 if category in self.draft and the_post.author.lower() != username.lower(): 55 55 # Block all access regardless 56 56 return False 57 57 … … 64 64 if category in self.draft: 65 65 if req.authname == 'anonymous': 66 66 return [(None, 'You need to be logged in to save as draft.')] 67 elif req.authname != fields['author']:67 elif req.authname.lower() != fields['author'].lower(): 68 68 return [(None, "Cannot save draft for an author that isn't you.")] 69 69 return []
Attachments (0)
Change History (6)
comment:1 Changed 8 years ago by
comment:3 follow-up: 4 Changed 8 years ago by
Does this patch work for you for both permission check and validation?
-
sample-plugins/BlogDraftPlugin.py
a b class BlogDraftPlugin(Component): 50 50 return 51 51 if resource.realm == 'blog' and resource.id: 52 52 the_post = BlogPost(self.env, resource.id, resource.version) 53 author = self.config.getbool('trac', 'ignore_auth_case') \ 54 and the_post.author.lower() or the_post.author 53 55 for category in the_post.category_list: 54 if category in self.draft and the_post.author != username:56 if category in self.draft and author != username: 55 57 # Block all access regardless 56 58 return False 57 59 … … class BlogDraftPlugin(Component): 60 62 def validate_blog_post(self, req, postname, version, fields): 61 63 """ If the post is a draft, just do some rudimentary checking to 62 64 make sure the author does not shoot him/herself in the foot. """ 65 author = self.config.getbool('trac', 'ignore_auth_case') \ 66 and fields['author'].lower() or fields['author'] 63 67 for category in _parse_categories(fields['categories']): 64 68 if category in self.draft: 65 69 if req.authname == 'anonymous': 66 70 return [(None, 'You need to be logged in to save as draft.')] 67 elif req.authname != fields['author']:71 elif req.authname != author: 68 72 return [(None, "Cannot save draft for an author that isn't you.")] 69 73 return []
comment:4 Changed 8 years ago by
Replying to osimons:
Does this patch work for you for both permission check and validation?
Confirmed. It works
Note: See
TracTickets for help on using
tickets.
Perhaps it is, at least if
[trac] ignore_auth_case = true
which should indicate that the case of usernames should be ignored on this installation. Add an extra conditional and only lowercase if this is enabled?If the setting is enabled, you obviously don't need to do
username.lower()
as this should already be done – only lowercase the author.