-
-
Notifications
You must be signed in to change notification settings - Fork 209
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
Conversation
(cherry picked from commit bd2873d)
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 600b259)
(cherry picked from commit 4eb21de)
(cherry picked from commit 05f0012)
(cherry picked from commit 9efddc6)
@@ -29,6 +29,7 @@ class UserTimelineEventType(Enum): | |||
RECORDING_RECOMMENDATION = 'recording_recommendation' | |||
FOLLOW = 'follow' | |||
LISTEN = 'listen' | |||
NOTIFICATION = 'notification' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spelling
There was a problem hiding this comment.
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: | ||
|
||
{ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
""" | ||
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.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
playlists?
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this correct?
There was a problem hiding this comment.
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.
There was a problem hiding this 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' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
No description provided.