[feature] Implement Mastodon-compatible roles (#3136)

* Implement Mastodon-compatible roles

- `Account.role` should only be available through verify_credentials for checking current user's permissions
- `Account.role` now carries a Mastodon-compatible permissions bitmap and a marker for whether it should be shown to the public
- `Account.roles` added for *public* display roles (undocumented but stable since Mastodon 4.1)
- Web template now uses only public display roles (no user-visible change here, we already special-cased the `user` role)

* Handle verify_credentials case for default role

* Update JSON exact-match tests

* Address review comments

* Add blocks bit to admin permissions bitmap
This commit is contained in:
Vyr Cossont
2024-07-31 09:26:09 -07:00
committed by GitHub
parent 2f7d654380
commit fd837776e2
12 changed files with 765 additions and 209 deletions

View File

@@ -157,7 +157,11 @@ func (suite *ReportsGetTestSuite) TestReportsGetAll() {
"locale": "",
"invite_request": null,
"role": {
"name": "user"
"id": "user",
"name": "user",
"color": "",
"permissions": "0",
"highlighted": false
},
"confirmed": false,
"approved": false,
@@ -198,7 +202,11 @@ func (suite *ReportsGetTestSuite) TestReportsGetAll() {
"locale": "en",
"invite_request": null,
"role": {
"name": "user"
"id": "user",
"name": "user",
"color": "",
"permissions": "0",
"highlighted": false
},
"confirmed": true,
"approved": true,
@@ -237,10 +245,7 @@ func (suite *ReportsGetTestSuite) TestReportsGetAll() {
"verified_at": null
}
],
"hide_collections": true,
"role": {
"name": "user"
}
"hide_collections": true
},
"created_by_application_id": "01F8MGY43H3N2C8EWPR2FPYEXG"
},
@@ -255,7 +260,11 @@ func (suite *ReportsGetTestSuite) TestReportsGetAll() {
"locale": "en",
"invite_request": null,
"role": {
"name": "admin"
"id": "admin",
"name": "admin",
"color": "",
"permissions": "546033",
"highlighted": true
},
"confirmed": true,
"approved": true,
@@ -284,9 +293,13 @@ func (suite *ReportsGetTestSuite) TestReportsGetAll() {
"emojis": [],
"fields": [],
"enable_rss": true,
"role": {
"name": "admin"
}
"roles": [
{
"id": "admin",
"name": "admin",
"color": ""
}
]
},
"created_by_application_id": "01F8MGXQRHYF5QPMTMXP78QC2F"
},
@@ -301,7 +314,11 @@ func (suite *ReportsGetTestSuite) TestReportsGetAll() {
"locale": "en",
"invite_request": null,
"role": {
"name": "admin"
"id": "admin",
"name": "admin",
"color": "",
"permissions": "546033",
"highlighted": true
},
"confirmed": true,
"approved": true,
@@ -330,9 +347,13 @@ func (suite *ReportsGetTestSuite) TestReportsGetAll() {
"emojis": [],
"fields": [],
"enable_rss": true,
"role": {
"name": "admin"
}
"roles": [
{
"id": "admin",
"name": "admin",
"color": ""
}
]
},
"created_by_application_id": "01F8MGXQRHYF5QPMTMXP78QC2F"
},
@@ -360,7 +381,11 @@ func (suite *ReportsGetTestSuite) TestReportsGetAll() {
"locale": "en",
"invite_request": null,
"role": {
"name": "user"
"id": "user",
"name": "user",
"color": "",
"permissions": "0",
"highlighted": false
},
"confirmed": true,
"approved": true,
@@ -399,10 +424,7 @@ func (suite *ReportsGetTestSuite) TestReportsGetAll() {
"verified_at": null
}
],
"hide_collections": true,
"role": {
"name": "user"
}
"hide_collections": true
},
"created_by_application_id": "01F8MGY43H3N2C8EWPR2FPYEXG"
},
@@ -417,7 +439,11 @@ func (suite *ReportsGetTestSuite) TestReportsGetAll() {
"locale": "",
"invite_request": null,
"role": {
"name": "user"
"id": "user",
"name": "user",
"color": "",
"permissions": "0",
"highlighted": false
},
"confirmed": false,
"approved": false,
@@ -605,7 +631,11 @@ func (suite *ReportsGetTestSuite) TestReportsGetCreatedByAccount() {
"locale": "en",
"invite_request": null,
"role": {
"name": "user"
"id": "user",
"name": "user",
"color": "",
"permissions": "0",
"highlighted": false
},
"confirmed": true,
"approved": true,
@@ -644,10 +674,7 @@ func (suite *ReportsGetTestSuite) TestReportsGetCreatedByAccount() {
"verified_at": null
}
],
"hide_collections": true,
"role": {
"name": "user"
}
"hide_collections": true
},
"created_by_application_id": "01F8MGY43H3N2C8EWPR2FPYEXG"
},
@@ -662,7 +689,11 @@ func (suite *ReportsGetTestSuite) TestReportsGetCreatedByAccount() {
"locale": "",
"invite_request": null,
"role": {
"name": "user"
"id": "user",
"name": "user",
"color": "",
"permissions": "0",
"highlighted": false
},
"confirmed": false,
"approved": false,
@@ -850,7 +881,11 @@ func (suite *ReportsGetTestSuite) TestReportsGetTargetAccount() {
"locale": "en",
"invite_request": null,
"role": {
"name": "user"
"id": "user",
"name": "user",
"color": "",
"permissions": "0",
"highlighted": false
},
"confirmed": true,
"approved": true,
@@ -889,10 +924,7 @@ func (suite *ReportsGetTestSuite) TestReportsGetTargetAccount() {
"verified_at": null
}
],
"hide_collections": true,
"role": {
"name": "user"
}
"hide_collections": true
},
"created_by_application_id": "01F8MGY43H3N2C8EWPR2FPYEXG"
},
@@ -907,7 +939,11 @@ func (suite *ReportsGetTestSuite) TestReportsGetTargetAccount() {
"locale": "",
"invite_request": null,
"role": {
"name": "user"
"id": "user",
"name": "user",
"color": "",
"permissions": "0",
"highlighted": false
},
"confirmed": false,
"approved": false,