-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Admin::EmailDomainBlock methods (#400)
* Add Admin::EmailDomainBlock entity * Add Admin::EmailDomainBlock methods * Add unit tests * Update documentation
- Loading branch information
1 parent
6fd3ac5
commit df7742b
Showing
11 changed files
with
479 additions
and
8 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
bigbone-rx/src/main/kotlin/social/bigbone/rx/admin/RxAdminEmailDomainBlockMethods.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package social.bigbone.rx.admin | ||
|
||
import io.reactivex.rxjava3.core.Completable | ||
import io.reactivex.rxjava3.core.Single | ||
import social.bigbone.MastodonClient | ||
import social.bigbone.api.Pageable | ||
import social.bigbone.api.Range | ||
import social.bigbone.api.entity.admin.AdminEmailDomainBlock | ||
import social.bigbone.api.method.admin.AdminEmailDomainBlockMethods | ||
|
||
/** | ||
* Reactive implementation of [AdminEmailDomainBlockMethods]. | ||
* | ||
* Disallow certain email domains from signing up. | ||
* | ||
* @see <a href="https://docs.joinmastodon.org/methods/admin/email_domain_blocks/">Mastodon admin/email_domain_blocks API methods</a> | ||
*/ | ||
class RxAdminEmailDomainBlockMethods(client: MastodonClient) { | ||
|
||
private val adminEmailDomainBlockMethods = AdminEmailDomainBlockMethods(client) | ||
|
||
/** | ||
* Show information about all email domains blocked from signing up. | ||
* | ||
* @param range optional Range for the pageable return value | ||
* | ||
* @see <a href="https://docs.joinmastodon.org/methods/admin/email_domain_blocks/#get">Mastodon API documentation: admin/email_domain_blocks/#get</a> | ||
*/ | ||
@JvmOverloads | ||
fun getAllEmailDomainBlocks(range: Range = Range()): Single<Pageable<AdminEmailDomainBlock>> = Single.fromCallable { | ||
adminEmailDomainBlockMethods.getAllEmailDomainBlocks(range).execute() | ||
} | ||
|
||
/** | ||
* Show information about a single email domain that is blocked from signups. | ||
* | ||
* @param id The ID of the EmailDomainBlock in the database. | ||
* @see <a href="https://docs.joinmastodon.org/methods/admin/email_domain_blocks/#get-one"> | ||
* Mastodon API documentation: admin/email_domain_blocks/#get-one</a> | ||
*/ | ||
fun getEmailDomainBlock(id: String): Single<AdminEmailDomainBlock> = Single.fromCallable { | ||
adminEmailDomainBlockMethods.getEmailDomainBlock(id).execute() | ||
} | ||
|
||
/** | ||
* Add a domain to the list of email domains blocked from signups. | ||
* | ||
* @param domain The domain to block federation with. | ||
* @see <a href="https://docs.joinmastodon.org/methods/admin/email_domain_blocks/#create">Mastodon API documentation: admin/email_domain_blocks/#create</a> | ||
*/ | ||
fun blockEmailDomain(domain: String): Single<AdminEmailDomainBlock> = Single.fromCallable { | ||
adminEmailDomainBlockMethods.blockEmailDomain(domain).execute() | ||
} | ||
|
||
/** | ||
* Lift a block against an email domain. | ||
* | ||
* @param id The ID of the EmailDomainBlock in the database. | ||
* | ||
* @see <a href="https://docs.joinmastodon.org/methods/admin/email_domain_blocks/#delete">Mastodon API documentation: admin/email_domain_blocks/#delete</a> | ||
*/ | ||
fun removeEmailDomainBlock(id: String) = Completable.fromAction { | ||
adminEmailDomainBlockMethods.removeEmailDomainBlock(id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
bigbone/src/main/kotlin/social/bigbone/api/entity/admin/AdminEmailDomainBlock.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package social.bigbone.api.entity.admin | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import social.bigbone.DateTimeSerializer | ||
import social.bigbone.PrecisionDateTime | ||
import social.bigbone.api.entity.data.History | ||
|
||
/** | ||
* Represents an email domain that cannot be used to sign up. | ||
* | ||
* @see <a href="https://docs.joinmastodon.org/entities/Admin_EmailDomainBlock/">Mastodon API Admin::EmailDomainBlock documentation</a> | ||
*/ | ||
@Serializable | ||
data class AdminEmailDomainBlock( | ||
/** | ||
* The ID of the EmailDomainBlock in the database. | ||
* String cast from an Integer, but not guaranteed to be a number. | ||
*/ | ||
@SerialName("id") | ||
val id: String, | ||
|
||
/** | ||
* The email domain that is not allowed to be used for signups. | ||
*/ | ||
@SerialName("domain") | ||
val domain: String, | ||
|
||
/** | ||
* The timestamp of the notification. | ||
*/ | ||
@SerialName("created_at") | ||
@Serializable(with = DateTimeSerializer::class) | ||
val createdAt: PrecisionDateTime = PrecisionDateTime.InvalidPrecisionDateTime.Unavailable, | ||
|
||
/** | ||
* Usage statistics for given days (typically the past week). | ||
*/ | ||
@SerialName("history") | ||
val history: List<History> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
bigbone/src/main/kotlin/social/bigbone/api/method/admin/AdminEmailDomainBlockMethods.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package social.bigbone.api.method.admin | ||
|
||
import social.bigbone.MastodonClient | ||
import social.bigbone.MastodonRequest | ||
import social.bigbone.Parameters | ||
import social.bigbone.api.Pageable | ||
import social.bigbone.api.Range | ||
import social.bigbone.api.entity.admin.AdminEmailDomainBlock | ||
|
||
/** | ||
* Disallow certain email domains from signing up. | ||
* | ||
* @see <a href="https://docs.joinmastodon.org/methods/admin/email_domain_blocks/">Mastodon admin/email_domain_blocks API methods</a> | ||
*/ | ||
class AdminEmailDomainBlockMethods(private val client: MastodonClient) { | ||
|
||
private val adminEmailDomainBlockEndpoint = "api/v1/admin/email_domain_blocks" | ||
|
||
/** | ||
* Show information about all email domains blocked from signing up. | ||
* | ||
* @param range optional Range for the pageable return value | ||
* | ||
* @see <a href="https://docs.joinmastodon.org/methods/admin/email_domain_blocks/#get">Mastodon API documentation: admin/email_domain_blocks/#get</a> | ||
*/ | ||
@JvmOverloads | ||
fun getAllEmailDomainBlocks(range: Range = Range()): MastodonRequest<Pageable<AdminEmailDomainBlock>> { | ||
return client.getPageableMastodonRequest( | ||
endpoint = adminEmailDomainBlockEndpoint, | ||
method = MastodonClient.Method.GET, | ||
parameters = range.toParameters() | ||
) | ||
} | ||
|
||
/** | ||
* Show information about a single email domain that is blocked from signups. | ||
* | ||
* @param id The ID of the EmailDomainBlock in the database. | ||
* @see <a href="https://docs.joinmastodon.org/methods/admin/email_domain_blocks/#get-one"> | ||
* Mastodon API documentation: admin/email_domain_blocks/#get-one</a> | ||
*/ | ||
fun getEmailDomainBlock(id: String): MastodonRequest<AdminEmailDomainBlock> { | ||
return client.getMastodonRequest( | ||
endpoint = "$adminEmailDomainBlockEndpoint/$id", | ||
method = MastodonClient.Method.GET | ||
) | ||
} | ||
|
||
/** | ||
* Add a domain to the list of email domains blocked from signups. | ||
* | ||
* @param domain The domain to block federation with. | ||
* @see <a href="https://docs.joinmastodon.org/methods/admin/email_domain_blocks/#create">Mastodon API documentation: admin/email_domain_blocks/#create</a> | ||
*/ | ||
fun blockEmailDomain(domain: String): MastodonRequest<AdminEmailDomainBlock> { | ||
return client.getMastodonRequest( | ||
endpoint = adminEmailDomainBlockEndpoint, | ||
method = MastodonClient.Method.POST, | ||
parameters = Parameters().append("domain", domain) | ||
) | ||
} | ||
|
||
/** | ||
* Lift a block against an email domain. | ||
* | ||
* @param id The ID of the EmailDomainBlock in the database. | ||
* | ||
* @see <a href="https://docs.joinmastodon.org/methods/admin/email_domain_blocks/#delete">Mastodon API documentation: admin/email_domain_blocks/#delete</a> | ||
*/ | ||
fun removeEmailDomainBlock(id: String) { | ||
client.performAction( | ||
endpoint = "$adminEmailDomainBlockEndpoint/$id", | ||
method = MastodonClient.Method.DELETE | ||
) | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
bigbone/src/test/assets/admin_email_domain_blocks_all_blocked_success.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
[ | ||
{ | ||
"id": "1", | ||
"domain": "foo", | ||
"created_at": "2022-11-16T06:09:36.176Z", | ||
"history": [ | ||
{ | ||
"day": "1668556800", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668470400", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668384000", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668297600", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668211200", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668124800", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668038400", | ||
"accounts": "0", | ||
"uses": "0" | ||
} | ||
] | ||
} | ||
] |
42 changes: 42 additions & 0 deletions
42
bigbone/src/test/assets/admin_email_domain_blocks_block_success.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"id": "1", | ||
"domain": "foo", | ||
"created_at": "2022-11-16T06:09:36.176Z", | ||
"history": [ | ||
{ | ||
"day": "1668556800", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668470400", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668384000", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668297600", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668211200", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668124800", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668038400", | ||
"accounts": "0", | ||
"uses": "0" | ||
} | ||
] | ||
} |
1 change: 1 addition & 0 deletions
1
bigbone/src/test/assets/admin_email_domain_blocks_delete_success.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
42 changes: 42 additions & 0 deletions
42
bigbone/src/test/assets/admin_email_domain_blocks_single_success.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"id": "1", | ||
"domain": "foo", | ||
"created_at": "2022-11-16T06:09:36.176Z", | ||
"history": [ | ||
{ | ||
"day": "1668556800", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668470400", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668384000", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668297600", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668211200", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668124800", | ||
"accounts": "0", | ||
"uses": "0" | ||
}, | ||
{ | ||
"day": "1668038400", | ||
"accounts": "0", | ||
"uses": "0" | ||
} | ||
] | ||
} |
Oops, something went wrong.