Opened 16 years ago

Closed 14 years ago

#6991 closed (fixed)

Omit redundant "if" judgements

Reported by: Liang Feng <hutuworm@…> Owned by: Alexander Koshelev
Component: contrib.admin Version: newforms-admin
Severity: Keywords: nfa-someday yandex-sprint ep2008
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Ramiro Morales)

django/contrib/admin/views/decorators.py:
if request.user.is_authenticated() and request.user.is_staff:

### COMMENT: request.user.is_staff is True implied that request.user.is_authenticated() is True, so request.user.is_authenticated() could be omitted.

docs/authentication.txt:
if not (request.user.is_authenticated() and request.user.has_perm('polls.can_vote')):

### COMMENT: request.user.has_perm('polls.can_vote') is True implied that request.user.is_authenticated() is True, so request.user.is_authenticated() could be omitted.

p.s. may save some precious cpu cycles on Google App Engine. :P

Attachments (2)

6991.diff (2.0 KB ) - added by Alexander Koshelev 16 years ago.
Patch for this ticket and #6990
6991.2.diff (3.3 KB ) - added by Ivan Sagalaev <Maniac@…> 16 years ago.
New patch with couple more places

Download all attachments as: .zip

Change History (10)

comment:1 by Ramiro Morales, 16 years ago

Description: modified (diff)

comment:2 by Karen Tracey <kmtracey@…>, 16 years ago

Keywords: nfa-someday added; Omit redundant "if" judgements removed
Triage Stage: UnreviewedDesign decision needed
Version: SVNnewforms-admin

Like #6990, these checks were not redundant before the fix for #3032. They are still there in newforms-admin so someone needs to decide if it is worth removing them.

comment:3 by Alexander Koshelev, 16 years ago

Owner: changed from nobody to Alexander Koshelev

by Alexander Koshelev, 16 years ago

Attachment: 6991.diff added

Patch for this ticket and #6990

comment:4 by Honza Král, 16 years ago

Has patch: set
Keywords: ep2008 added
Patch needs improvement: set
Triage Stage: Design decision neededAccepted

After #3032 being fixed, this is really trivial, all tests pass. Just make sure to catch every occurrence of this behavior.

by Ivan Sagalaev <Maniac@…>, 16 years ago

Attachment: 6991.2.diff added

New patch with couple more places

comment:5 by Ivan Sagalaev <Maniac@…>, 16 years ago

Patch needs improvement: unset

Catched couple more places. Looks like they're all here.
Honza mentioned create_update.py in generic views but there are only standalone request.user.is_authenticated() checks that are all needed.

comment:6 by Honza Král, 16 years ago

Triage Stage: AcceptedReady for checkin

thanks

comment:7 by Ivan Sagalaev <Maniac@…>, 16 years ago

Keywords: yandex-sprint added

comment:8 by Adrian Holovaty, 14 years ago

Resolution: fixed
Status: newclosed

(In [12142]) Fixed #6991 -- Removed some redundant user.is_authenticated() calls in various places. Thanks, alexkoshelev, Liang Feng and Ivan Sagalaev

Note: See TracTickets for help on using tickets.
Back to Top