From 87ff0107c15c06dc6e48c7c304e3ffe7e2629684 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin <godfat@godfat.org> Date: Thu, 31 Mar 2016 22:10:42 +0800 Subject: [PATCH] Raise one by one instead of if checks --- lib/gitlab/email/receiver.rb | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/gitlab/email/receiver.rb b/lib/gitlab/email/receiver.rb index 3dd3bd02707..5b55a045cbe 100644 --- a/lib/gitlab/email/receiver.rb +++ b/lib/gitlab/email/receiver.rb @@ -76,16 +76,11 @@ module Gitlab end def validate_permission(author, project, permission) - if author - if author.blocked? - raise UserBlockedError - elsif project.nil? || !author.can?(permission, project) - # TODO: Give project not found error if author cannot read project - raise UserNotAuthorizedError - end - else - raise UserNotFoundError - end + raise UserNotFoundError unless author + raise UserBlockedError if author.blocked? + # TODO: Give project not found error if author cannot read project + raise UserNotAuthorizedError if project.nil? || + !author.can?(permission, project) end # Find the first matched user in database from email From: section -- GitLab