#2180 WIP: Remove duplicated code from issues API
Merged by pingou. Opened by mbasti.
mbasti/pagure duplication-cleanup  into  master

Download 2180.patch

Blocker for following issues (no more duplicated code):

  • https://pagure.io/pagure/issue/2178
  • https://pagure.io/pagure/issue/2177
  • https://pagure.io/pagure/issue/2176
  • https://pagure.io/pagure/issue/2175

Duplicated code is ugly, hard to maintain, error prone, unreadable and http://i0.kym-cdn.com/photos/images/newsfeed/001/209/105/7b2.jpeg

test

newline

newline

Duplicated code is ugly, hard to maintain, error prone, unreadable and http://i0.kym-cdn.com/photos/images/newsfeed/001/209/105/7b2.jpeg

Why can't you just contribute to a project without making snarky comment? Seriously, this isn't fun when you're on the receiving end of it.

Sorry :cry:

API endpoint requiring a token should have it declared with a decorator, so this is only to check that the token correspond to the expected project.

Here we enforce the presence of the API token :)

Missing _check_repo no?

This check seems to have been lost

This has been lost as well

The check is required, we have API token specific to some project and project-less API token

Same as above :)

And here :)

To fix indeed

To fix indeed

Nope (if you mean _check_token), It was moved to earlier place in "issues API: performace: fail early with invalid token", see line 183

It is part of _get_repo() should I extract it into separate function?

_get_repo() contains it

Same reply as above :)

here too :)

Maybe then I should create a _check_token(require_project_token=True) and cover both cases in that function

require_project_token=False in this case

Ok, should be there if api_authenticated() as in code later for non-project token?

Isn't then if api_authenticated() duplication when api must be authenticated already as enfoce decorators, or if decorator allows unathenticated querys should be check for repo really there for authenticated?

Thanks for explanation

Ok, I see, thanks

Might make sense, because then we could move get_repo to api/init and re-use it in other API controller

Sounds doable, though I'd suggest a slightly shorter variable name, maybe project_token?

Well, thanks for the patch :)

sounds good

rebased

Unresolved previously:

 pingou commented 2 days ago
API endpoint requiring a token should have it declared with a decorator, so this is only to check that the token correspond to the expected project.
 mbasti commented 2 days ago
Isn't then if api_authenticated() duplication when api must be authenticated already as enfoce decorators, or if decorator allows unathenticated querys should be check for repo really there for authenticated?

10 new commits added

  • NEEDINFO
  • issues API: extract issue tracker check to separate function
  • issues API: update _check_token to support non-project tokens
  • issues API: require repo_commiter not repo_admin privileges
  • issues API: deduplicate issue access check
  • unify argument of is_repo_commiter
  • issues api: deduplicate getting issues
  • issues API: performace: fail early with invalid token
  • issues api: deduplicate checking of token
  • issues api: deduplicate of getting repository

For this one no, we must be authenticated which should be ensured by @api_login_required

rebased

rebased

rebased

I'd say this is the final version

pretty please pagure-ci rebuild

Thanks pagure-ci :)

This is looking all good to me as well, let's merge!

Pull-Request has been merged by pingou

Well, thank you, this is a pretty awesome PR :)

Metadata