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

Add api endpoint for approved bots to post on user's timeline #1342

Merged
merged 9 commits into from
Mar 25, 2021
Merged

Conversation

amCap1712
Copy link
Member

No description provided.

Instantiating the union type only works if it contains a single type
otherwise we need to instantiate the actual type.

(cherry picked from commit 4e741aa)
(cherry picked from commit 05f0012)
(cherry picked from commit 9efddc6)
@amCap1712 amCap1712 requested a review from mayhem March 15, 2021 11:42
@@ -29,6 +29,7 @@ class UserTimelineEventType(Enum):
RECORDING_RECOMMENDATION = 'recording_recommendation'
FOLLOW = 'follow'
LISTEN = 'listen'
NOTIFICATION = 'notification'
Copy link
Collaborator

Choose a reason for hiding this comment

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

why does this enum have 4 items but the database enum only has recording_recommendation and notification?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that's because the follow event is a relationship and hence in the user_relationship_enum. The listen event is not stored separately in the database and the remaining two are in the user_timeline_event_type_enum.

link: str


UserTimelineEventMetadata = Union[RecordingRecommendationMetadata, NotificationMetadata]


class UserTimelineEvent(pydantic.BaseModel):
Copy link
Collaborator

Choose a reason for hiding this comment

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

not directly related to this PR, but I see that in this class created is a datetime, whereas in APIFollowEvent it's an int. why is this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I do not know why that is. maybe @mayhem or @paramsingh know?

Copy link
Member

Choose a reason for hiding this comment

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

Not a clue. We love our timestamp/datetime confusion in LB, that's for sure.


{
"metadata": {
"message": <the message ot post, required>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

spelling

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.


The request should contain the following data:

{
Copy link
Collaborator

Choose a reason for hiding this comment

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

how will this format in the documentation? It might need a prefix to tell it to highlight it as json

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it should show correctly as this does here

"""
creator = validate_auth_header()
if creator["musicbrainz_id"] not in current_app.config['APPROVED_PLAYLIST_BOTS']:
raise APIUnauthorized("Only approved users are allowed to submit playlists made for someone else.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

playlists?

Copy link
Member Author

Choose a reason for hiding this comment

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

The intent of this endpoint was to allow troi-bot to post playlists but since we use notification everywhere hence the mistake. Fixed.


try:
metadata = NotificationMetadata(creator_id=creator['id'], message=data['message'], link=data['link'])
except pydantic.ValidationError as e:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I really like this way of using pydantic to validate the input data!

}
}

:param user_name: The MusicBrainz ID of the user who is recommending the recording.
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, that's incorrect. Fixed.

Copy link
Member

@mayhem mayhem left a comment

Choose a reason for hiding this comment

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

Still needs one test fixed.

metadata=NotificationMetadata(
creator_id=self.user['id'],
message='Test Message',
link='Test Link'
Copy link
Member

Choose a reason for hiding this comment

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

link should also be removed from here.

Copy link
Member

Choose a reason for hiding this comment

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

This may be the reason for the test failure...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants