diff options
author | halcy <halcy@ARARAGI-KUN> | 2022-11-26 01:00:44 +0200 |
---|---|---|
committer | halcy <halcy@ARARAGI-KUN> | 2022-11-26 01:00:44 +0200 |
commit | 7331f7774ae10d927e086318338989de6bc37cad (patch) | |
tree | 6444e7070e1f8e7fa1abdaae771c76bde8896892 /mastodon | |
parent | 0c731e968b652de7e90312b744277b33788d6ddd (diff) | |
download | mastodon.py-7331f7774ae10d927e086318338989de6bc37cad.tar.gz |
Add admin domain block tests, change some things about the admin domain blocks
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index c519a0d..82e058c 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -210,10 +210,20 @@ class Mastodon: | |||
210 | 'admin:read': [ | 210 | 'admin:read': [ |
211 | 'admin:read:accounts', | 211 | 'admin:read:accounts', |
212 | 'admin:read:reports', | 212 | 'admin:read:reports', |
213 | 'admin:read:domain_allows', | ||
214 | 'admin:read:domain_blocks', | ||
215 | 'admin:read:ip_blocks', | ||
216 | 'admin:read:email_domain_blocks', | ||
217 | 'admin:read:canonical_email_blocks', | ||
213 | ], | 218 | ], |
214 | 'admin:write': [ | 219 | 'admin:write': [ |
215 | 'admin:write:accounts', | 220 | 'admin:write:accounts', |
216 | 'admin:write:reports', | 221 | 'admin:write:reports', |
222 | 'admin:write:domain_allows', | ||
223 | 'admin:write:domain_blocks', | ||
224 | 'admin:write:ip_blocks', | ||
225 | 'admin:write:email_domain_blocks', | ||
226 | 'admin:write:canonical_email_blocks', | ||
217 | ], | 227 | ], |
218 | } | 228 | } |
219 | __VALID_SCOPES = ['read', 'write', 'follow', 'push', 'admin:read', 'admin:write'] + \ | 229 | __VALID_SCOPES = ['read', 'write', 'follow', 'push', 'admin:read', 'admin:write'] + \ |
@@ -253,6 +263,7 @@ class Mastodon: | |||
253 | __DICT_VERSION_REACTION = "3.1.0" | 263 | __DICT_VERSION_REACTION = "3.1.0" |
254 | __DICT_VERSION_ANNOUNCEMENT = bigger_version("3.1.0", __DICT_VERSION_REACTION) | 264 | __DICT_VERSION_ANNOUNCEMENT = bigger_version("3.1.0", __DICT_VERSION_REACTION) |
255 | __DICT_VERSION_STATUS_EDIT = "3.5.0" | 265 | __DICT_VERSION_STATUS_EDIT = "3.5.0" |
266 | __DICT_VERSION_ADMIN_DOMAIN_BLOCK = "4.0.0" | ||
256 | 267 | ||
257 | ### | 268 | ### |
258 | # Registering apps | 269 | # Registering apps |
@@ -3363,26 +3374,26 @@ class Mastodon: | |||
3363 | params = self.__generate_params(locals()) | 3374 | params = self.__generate_params(locals()) |
3364 | return self.__api_request('GET', '/api/v1/admin/trends/links', params) | 3375 | return self.__api_request('GET', '/api/v1/admin/trends/links', params) |
3365 | 3376 | ||
3366 | @api_version("4.0.0","4.0.0","4.0.0") | 3377 | @api_version("4.0.0", "4.0.0", __DICT_VERSION_ADMIN_DOMAIN_BLOCK) |
3367 | def admin_domain_blocks(self, id:str=None, limit:int=None): | 3378 | def admin_domain_blocks(self, id=None, limit:int=None): |
3368 | """ | 3379 | """ |
3369 | Fetches a list of blocked domains. Requires scope `admin:read:domain_blocks`. | 3380 | Fetches a list of blocked domains. Requires scope `admin:read:domain_blocks`. |
3370 | 3381 | ||
3371 | Provide an `id` to fetch a specific domain block based on its database id. | 3382 | Provide an `id` to fetch a specific domain block based on its database id. |
3372 | 3383 | ||
3373 | Returns a list of `domain dicts`_, or 404 if a domain is queried for and not found. | 3384 | Returns a list of `admin domain block dicts`_, raises a `MastodonAPIError` if the specified block does not exist. |
3374 | """ | 3385 | """ |
3375 | id = self.__unpack_id(id) | ||
3376 | if id is not None: | 3386 | if id is not None: |
3387 | id = self.__unpack_id(id) | ||
3377 | return self.__api_request('GET', '/api/v1/admin/domain_blocks/{0}'.format(id)) | 3388 | return self.__api_request('GET', '/api/v1/admin/domain_blocks/{0}'.format(id)) |
3378 | else: | 3389 | else: |
3379 | params = self.__generate_params(locals(),['limit']) | 3390 | params = self.__generate_params(locals(),['limit']) |
3380 | return self.__api_request('GET', '/api/v1/admin/domain_blocks/', params) | 3391 | return self.__api_request('GET', '/api/v1/admin/domain_blocks/', params) |
3381 | 3392 | ||
3382 | @api_version("4.0.0","4.0.0","4.0.0") | 3393 | @api_version("4.0.0", "4.0.0", __DICT_VERSION_ADMIN_DOMAIN_BLOCK) |
3383 | def admin_domain_block(self, domain:str, severity:str=None, reject_media:bool=None, reject_reports:bool=None, private_comment:str=None, public_comment:str=None, obfuscate:bool=None): | 3394 | def admin_create_domain_block(self, domain:str, severity:str=None, reject_media:bool=None, reject_reports:bool=None, private_comment:str=None, public_comment:str=None, obfuscate:bool=None): |
3384 | """ | 3395 | """ |
3385 | Perform a moderation action on a domain. | 3396 | Perform a moderation action on a domain. Requires scope `admin:write:domain_blocks`. |
3386 | 3397 | ||
3387 | Valid severities are: | 3398 | Valid severities are: |
3388 | * "silence" - hide all posts from federated timelines and do not show notifications to local users from the remote instance's users unless they are following the remote user. | 3399 | * "silence" - hide all posts from federated timelines and do not show notifications to local users from the remote instance's users unless they are following the remote user. |
@@ -3395,20 +3406,19 @@ class Mastodon: | |||
3395 | `reject_reports` ignores all reports from the remote instance. | 3406 | `reject_reports` ignores all reports from the remote instance. |
3396 | `private_comment` sets a private admin comment for the domain. | 3407 | `private_comment` sets a private admin comment for the domain. |
3397 | `public_comment` sets a publicly available comment for this domain, which will be available to local users and may be available to everyone depending on your settings. | 3408 | `public_comment` sets a publicly available comment for this domain, which will be available to local users and may be available to everyone depending on your settings. |
3398 | `obfuscate` sensors some part of the domain name. Useful if the domain name contains unwanted words like slurs. | 3409 | `obfuscate` censors some part of the domain name. Useful if the domain name contains unwanted words like slurs. |
3410 | |||
3411 | Returns the new domain block as an `admin domain block dict`_. | ||
3399 | """ | 3412 | """ |
3400 | if domain is None: | 3413 | if domain is None: |
3401 | raise AttributeError("Must provide a domain to block a domain") | 3414 | raise AttributeError("Must provide a domain to block a domain") |
3402 | |||
3403 | params = self.__generate_params(locals()) | 3415 | params = self.__generate_params(locals()) |
3416 | return self.__api_request('POST', '/api/v1/admin/domain_blocks/', params) | ||
3404 | 3417 | ||
3405 | 3418 | @api_version("4.0.0", "4.0.0", __DICT_VERSION_ADMIN_DOMAIN_BLOCK) | |
3406 | self.__api_request('POST', '/api/v1/admin/domain_blocks/', params) | 3419 | def admin_update_domain_block(self, id, severity:str=None, reject_media:bool=None, reject_reports:bool=None, private_comment:str=None, public_comment:str=None, obfuscate:bool=None): |
3407 | |||
3408 | @api_version("4.0.0","4.0.0","4.0.0") | ||
3409 | def admin_update_domain_block(self, id:str, severity:str=None, reject_media:bool=None, reject_reports:bool=None, private_comment:str=None, public_comment:str=None, obfuscate:bool=None): | ||
3410 | """ | 3420 | """ |
3411 | Modify existing moderation action on a domain. | 3421 | Modify existing moderation action on a domain. Requires scope `admin:write:domain_blocks`. |
3412 | 3422 | ||
3413 | Valid severities are: | 3423 | Valid severities are: |
3414 | * "silence" - hide all posts from federated timelines and do not show notifications to local users from the remote instance's users unless they are following the remote user. | 3424 | * "silence" - hide all posts from federated timelines and do not show notifications to local users from the remote instance's users unless they are following the remote user. |
@@ -3421,27 +3431,28 @@ class Mastodon: | |||
3421 | `reject_reports` ignores all reports from the remote instance. | 3431 | `reject_reports` ignores all reports from the remote instance. |
3422 | `private_comment` sets a private admin comment for the domain. | 3432 | `private_comment` sets a private admin comment for the domain. |
3423 | `public_comment` sets a publicly available comment for this domain, which will be available to local users and may be available to everyone depending on your settings. | 3433 | `public_comment` sets a publicly available comment for this domain, which will be available to local users and may be available to everyone depending on your settings. |
3424 | `obfuscate` sensors some part of the domain name. Useful if the domain name contains unwanted words like slurs. | 3434 | `obfuscate` censors some part of the domain name. Useful if the domain name contains unwanted words like slurs. |
3435 | |||
3436 | Returns the modified domain block as an `admin domain block dict`_, raises a `MastodonAPIError` if the specified block does not exist. | ||
3425 | """ | 3437 | """ |
3426 | if id is None: | 3438 | if id is None: |
3427 | raise AttributeError("Must provide an id to modify the existing moderation actions on a given domain.") | 3439 | raise AttributeError("Must provide an id to modify the existing moderation actions on a given domain.") |
3440 | id = self.__unpack_id(id) | ||
3441 | params = self.__generate_params(locals(), ["id"]) | ||
3442 | return self.__api_request('PUT', '/api/v1/admin/domain_blocks/{0}'.format(id), params) | ||
3428 | 3443 | ||
3429 | params = self.__generate_params(locals()) | 3444 | @api_version("4.0.0", "4.0.0", __DICT_VERSION_ADMIN_DOMAIN_BLOCK) |
3430 | 3445 | def admin_delete_domain_block(self, id=None): | |
3431 | self.__api_request('PUT', '/api/v1/admin/domain_blocks/', params) | ||
3432 | |||
3433 | @api_version("4.0.0","4.0.0","4.0.0") | ||
3434 | def admin_delete_domain_blocks(self, id:str=None): | ||
3435 | """ | 3446 | """ |
3436 | Removes moderation action against a given domain. Requires scope `admin:write:domain_blocks`. | 3447 | Removes moderation action against a given domain. Requires scope `admin:write:domain_blocks`. |
3437 | 3448 | ||
3438 | Provide an `id` to remove a specific domain block based on its database id. | 3449 | Provide an `id` to remove a specific domain block based on its database id. |
3439 | 3450 | ||
3440 | Returns 200 OK if successful. | 3451 | Raises a `MastodonAPIError` if the specified block does not exist. |
3441 | """ | 3452 | """ |
3442 | id = self.__unpack_id(id) | ||
3443 | if id is not None: | 3453 | if id is not None: |
3444 | return self.__api_request('DELETE', '/api/v1/admin/domain_blocks/{0}'.format(id)) | 3454 | id = self.__unpack_id(id) |
3455 | self.__api_request('DELETE', '/api/v1/admin/domain_blocks/{0}'.format(id)) | ||
3445 | else: | 3456 | else: |
3446 | raise AttributeError("You must provide an id of an existing domain block to remove it.") | 3457 | raise AttributeError("You must provide an id of an existing domain block to remove it.") |
3447 | 3458 | ||