Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Simplify curation access #442

Merged
merged 7 commits into from
Mar 17, 2022
Merged

Conversation

LautaroPetaccio
Copy link
Contributor

@LautaroPetaccio LautaroPetaccio commented Mar 16, 2022

This PR does the following:

  • Fixes Fix pushing of TP items changes #441 by removing an unused call to the third party api.
  • Simplifies the requests to the catalyst by removing the getMergedItem request as getting the item was not required.
  • Makes the getMergedCollection get a collection instead of an id so it can be used without re-asking for the collection in the database.
  • Moves URN helpers to an URN utils file to solve a cyclic dependency.
  • Makes the hasAccess methods for the items and the collections usable if the collection given to them is not published.

@coveralls
Copy link

coveralls commented Mar 16, 2022

Pull Request Test Coverage Report for Build 2000808759

  • 64 of 73 (87.67%) changed or added relevant lines in 16 files are covered.
  • 11 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.2%) to 68.159%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/Curation/Curation.router.ts 7 8 87.5%
src/Item/access.ts 2 3 66.67%
src/utils/urn.ts 25 26 96.15%
src/Collection/Collection.model.ts 1 3 33.33%
src/Curation/Curation.service.ts 9 13 69.23%
Files with Coverage Reduction New Missed Lines %
src/ethereum/api/Bridge.ts 2 87.2%
src/Item/Item.errors.ts 2 95.45%
src/ethereum/api/peer.ts 3 39.29%
src/server.ts 4 89.55%
Totals Coverage Status
Change from base Build 1994793877: 0.2%
Covered Lines: 2330
Relevant Lines: 3268

💛 - Coveralls

Copy link
Contributor

@nicosantangelo nicosantangelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome !

@@ -25,6 +26,18 @@ export class Collection extends Model<CollectionAttributes> {
WHERE contract_address = ANY(${contractAddresses})`)
}

static async findCollectionOwningItem(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this name, but I think we were using ByXXX if you want to be consistent ( findByItemId )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to findByItemId!

@@ -25,7 +25,7 @@ export async function hasAccess(
isCommitteeMember(eth_address),
isTPCollection(collection)
? thirdPartyAPI.isManager(collection.third_party_id, eth_address)
: isManager(eth_address, collection),
: !!collection.is_published && isManager(eth_address, collection),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if I understand this condition:

  • Why are we casting a (supposedly) boolean value? might be badly typed

image

- For what I can tell, this is so checking for managers makes sense. Meaning that only published collections have managers. But reading the code, shouldn't `isManager()` just return false then?

Copy link
Contributor Author

@LautaroPetaccio LautaroPetaccio Mar 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that isManager should only be called with a merged collection. The code should be something like isMergedCollection(collection) && isManager(eth_address, collection).
I could add this function elsewhere, but I would love to do it with some type changes to collection first.
Check related comment down below.

} else if (error instanceof HTTPError) {
throw error
} else {
throw new HTTPError(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question! why is this the only place where we're doing this? meaning checking for HTTPErrors and throwing a new one otherwise.

It seems like the code in insertCuration should do the same ( if (error instanceof HTTPError) )? and the other catches might need to throw a new HTTPError instead of throw error ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! moved it to validateAccessToCuration so the errors can get catched every time.

@@ -1,5 +1,5 @@
import { Model, SQL, raw } from 'decentraland-server'
import { Collection } from '../Collection'
import { Collection } from '../Collection/Collection.model'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

circular dep?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly there are a lot of circular dependencies between item and collection. I can't remember if this one was impacting our tests, but I tried to reduce them as much as possible.

@@ -37,7 +50,8 @@ export async function hasAccess(
eth_address
)
} else {
isManager = isCollectionManager(eth_address, collection)
isManager =
collection.is_published && isCollectionManager(eth_address, collection)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question as here

Also, reading here, it seems odd that checking for is_published seems to be required for calling isManager, if it's a MUST maybe it should be in the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that there's an issue with the types here. The method is taking CollectionAttributes as the parameter for its type, but CollectionAttributes is not correctly typed, it has properties like managers, is_published and is_approved that don't live in the database, making is_published possibly null.
We need to fix the collection types to be able to represented a MergedCollection containing all of these values and a real CollectionAttributes object, but this PR has gotten pretty long already.

@LautaroPetaccio LautaroPetaccio merged commit 40b46ea into master Mar 17, 2022
@LautaroPetaccio LautaroPetaccio deleted the fix/simplify-curation-access branch March 17, 2022 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix pushing of TP items changes
3 participants