Skip to content

Commit

Permalink
Finish admin models
Browse files Browse the repository at this point in the history
 - EmailDomainBlock
 - IpBlock
 - Measure
 - Report
  • Loading branch information
wingio committed Dec 20, 2023
1 parent 67c2675 commit 82f0b40
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package xyz.wingio.fediapi.software.mastodon.model.admin

import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import xyz.wingio.fediapi.Language
import xyz.wingio.fediapi.software.mastodon.model.Role
import xyz.wingio.fediapi.software.mastodon.model.account.Account
Expand All @@ -28,6 +29,7 @@ import xyz.wingio.fediapi.software.mastodon.model.account.Account
* @param createdByApplicationId The ID of the [Application] that created this account, if applicable
* @param invitedByAccountId The ID of the [Account] that invited this user, if applicable.
*/
@Serializable
public data class AdminAccount(
val id: String,
val username: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public data class DomainBlock(
val obfuscate: Boolean
) {

@Serializable
public enum class Severity {
/**
* Account statuses from this domain will be hidden by default
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package xyz.wingio.fediapi.software.mastodon.model.admin

import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* Represents an email domain that cannot be used to sign up.
*
* @param id The ID of the [EmailDomainBlock] in the database.
* @param domain The email domain that is not allowed to be used for signups.
* @param createdAt When the email domain was disallowed from signups.
* @param history Usage statistics for given days (typically the past week).
*/
@Serializable
public data class EmailDomainBlock(
val id: String,
val domain: String,
@SerialName("created_at") val createdAt: Instant,
val history: History
) {

/**
* Usage statistics for an [EmailDomainBlock]
*
* @param day UNIX timestamp on midnight of the given day.
* @param accounts The counted accounts signup attempts using that email domain within that day.
* @param uses The counted IP signup attempts of that email domain within that day.
*/
@Serializable
public data class History(
val day: String? = null,
val accounts: String? = null,
val uses: String? = null
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package xyz.wingio.fediapi.software.mastodon.model.admin

import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* Represents an IP address range that cannot be used to sign up.
*
* @param id The ID of the [DomainBlock] in the database.
* @param ip The IP address range that is not allowed to federate.
* @param severity The associated policy with this IP block.
* @param comment The recorded reason for this IP block.
* @param createdAt When the IP block was created.
* @param expiresAt When the IP block will expire.
*/
@Serializable
public data class IpBlock(
val id: String,
val ip: String,
val severity: Severity,
val comment: String,
@SerialName("created_at") val createdAt: Instant,
@SerialName("expires_at") val expiresAt: Instant?
) {

@Serializable
public enum class Severity {
/**
* Any signup from this IP range will create a pending account
*/
@SerialName("sign_up_requires_approval") SIGNUP_REQUIRES_APPROVAL,

/**
* Any signup from this IP range will be rejected
*/
@SerialName("sign_up_block") SIGNUP_BLOCKED,

/**
* Any activity from this IP range will be rejected entirely
*/
@SerialName("no_access") NO_ACCESS
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package xyz.wingio.fediapi.software.mastodon.model.admin

import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* Represents quantitative data about the server.
*
* @param key The unique keystring for the requested measure.
* @param unit The units associated with this data item’s value, if applicable.
* @param total The numeric total associated with the requested measure.
* @param humanValue A human-readable formatted value for this data item.
* @param previousTotal The numeric total associated with the requested measure, in the previous period. Previous period is calculated by subtracting the startAt and endAt dates, then offsetting both start and end dates backwards by the length of the time period.
* @param data The data available for the requested measure, split into daily buckets.
*/
@Serializable
public data class Measure(
val key: String,
val unit: String?,
val total: String,
@SerialName("human_value") val humanValue: String? = null,
@SerialName("previous_total") val previousTotal: String? = null,
val data: List<Data>
) {

/**
* The data available for a single day
*
* @param date Midnight on the requested day in the time period.
* @param value The numeric value for the requested measure.
*/
@Serializable
public data class Data(
val date: Instant,
val value: String,
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package xyz.wingio.fediapi.software.mastodon.model.admin

import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* Admin-level information about a filed report.
*
* @param id The ID of the report in the database.
* @param actionTaken Whether an action was taken to resolve this report.
* @param actionTakenAt When an action was taken, if this report is currently resolved.
* @param category The category under which the report is classified.
* @param comment An optional reason for reporting.
* @param forwarded Whether a report was forwarded to a remote instance.
* @param createdAt The time the report was filed.
* @param updatedAt The time of last action on this report.
* @param account The account which filed the report.
* @param targetAccount The account being reported.
* @param assignedAccount The account of the moderator assigned to this report.
* @param actionTakenByAccount The account of the moderator who handled the report.
* @param statuses Statuses attached to the report, for context.
* @param rules Rules attached to the report, for context.
*/
@Serializable
public data class Report(
val id: String,
@SerialName("action_taken") val actionTaken: Boolean,
@SerialName("action_taken_at") val actionTakenAt: Instant?,
val category: Category,
val comment: String,
val forwarded: Boolean,
@SerialName("created_at") val createdAt: Instant,
@SerialName("updated_at") val updatedAt: Instant,
val account: AdminAccount,
@SerialName("target_account") val targetAccount: AdminAccount,
@SerialName("assigned_account") val assignedAccount: AdminAccount?,
@SerialName("action_taken_by_account") val actionTakenByAccount: AdminAccount?,
val statuses: List<String>, // TODO: Model
val rules: List<String> // TODO: Model
) {

@Serializable
public enum class Category {
/**
* Malicious, fake, or repetitive content
*/
@SerialName("spam") SPAM,

/**
* Violates one or more specific [rules]
*/
@SerialName("violation") VIOLATION,

/**
* The default (catch-all) category
*/
@SerialName("other") OTHER
}

}

0 comments on commit 82f0b40

Please sign in to comment.