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

feat(api): Add endpoint for GetComments #2552

Merged
merged 39 commits into from
Sep 16, 2024

Conversation

ioslife
Copy link
Contributor

@ioslife ioslife commented Jul 10, 2024

To address: #2081 (comment)

*  API_GetComments - returns the comments associated to a game or achievement
*    i : game or achievement id
*    u : username
*    t : 1 = game, 2 = achievement, 3 = user
*    o : offset - number of entries to skip (default: 0)
*    c : count - number of entries to return (default: 100, max: 500)
*
*  int         Count                       number of comment records returned in the response
*  int         Total                       number of comment records the game/achievement/user actually has overall
*  array       Results
*   object      [value]
*    int         User                      username of the commenter
*    string      Submitted                 date time the comment was submitted
*    string      CommentText               text of the comment
*/

@ioslife
Copy link
Contributor Author

ioslife commented Jul 10, 2024

I broke my tests before the last push. Fixing now.

Copy link
Member

@wescopeland wescopeland left a comment

Choose a reason for hiding this comment

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

This endpoint surfaces multiple security issues.

Comments for banned users are still returned even though they're invisible in the UI. Comments for users are still returned if they have their wall disabled.

@ioslife ioslife marked this pull request as draft July 10, 2024 18:30
@ioslife
Copy link
Contributor Author

ioslife commented Jul 10, 2024

I've converted this to a draft for now. After talking with Wes, there is a bigger effort going on to deprecate Permissions and start using Policies.

resources/views/components/comment/item.blade.php first needs to be refactored to use policies.
This is nontrivial because there are multiple types of commentables and different policies mapping to each.
  • comments from Wes

I will keep looking at this, but it's getting to a point that is out of my wheel house. I'd love for someone to work with me to make sure we get this done properly.

@ioslife ioslife marked this pull request as ready for review July 31, 2024 15:28
@ioslife
Copy link
Contributor Author

ioslife commented Aug 6, 2024

docs: RetroAchievements/api-docs#59

app/Models/Comment.php Outdated Show resolved Hide resolved
@wescopeland
Copy link
Member

Not entirely sure what I'm doing wrong:

http://localhost:64000/API/API_GetComments.php?z=...&y=...&i=1&t=1
{
	"message": "App\\Models\\User::getUsernameAttribute(): Return value must be of type string, null returned",
	"exception": "TypeError",
	"file": "/var/www/html/app/Models/User.php",
	"line": 412,
	"trace": [
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php",
			"line": 658,
			"function": "getUsernameAttribute",
			"class": "App\\Models\\User",
			"type": "->"
		},
... a bunch of stuff

app/Policies/CommentPolicy.php Show resolved Hide resolved
database/factories/CommentFactory.php Outdated Show resolved Hide resolved
public/API/API_GetComments.php Show resolved Hide resolved
Copy link
Member

@wescopeland wescopeland left a comment

Choose a reason for hiding this comment

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

This is looking a lot better. I've spent some time trying to break things and I'm not able to. I have only one (minor) suggested refactor from this final review and then I think we'll be in good shape.

public/API/API_GetComments.php Outdated Show resolved Hide resolved
@wescopeland wescopeland merged commit 51373e0 into RetroAchievements:master Sep 16, 2024
6 checks passed
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.

2 participants