Skip to content

fix: privacy module requests #841

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

Merged
merged 6 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ arisa:

privacy:
message: panel-mark-private
commentMessage: panel-mark-private-comment
commentNote: |-

----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.github.mojira.arisa.apiclient.models.IssueLink
import io.github.mojira.arisa.apiclient.models.User
import io.github.mojira.arisa.apiclient.models.Visibility
import io.github.mojira.arisa.apiclient.requestModels.*
import io.github.mojira.arisa.log
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
Expand Down Expand Up @@ -151,6 +152,7 @@ private inline fun <reified T> Call<T>.executeOrThrow(): T {

if (!response.isSuccessful) {
if (response.code() in 400..499) {
response.errorBody()?.let { log.error(it.string()) }
throw ClientErrorException(
response.code(),
"Request failed - [${response.code()}] ${originalRequest.method} ${originalRequest.url}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ object Arisa : ConfigSpec() {
val message by required<String>(
description = "The key of the message that is posted when this module succeeds."
)
val commentMessage by required<String>(
description = "The key of the message that is posted when this module detects sensitive data within" +
"the comment."
)
val commentNote by optional(
"",
description = "The text which will be appended at the comments that are restricted by this module."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,8 @@ fun restrictCommentToGroup(
val payload = UpdateCommentBody(
body,
visibility = Visibility(
identifier = group,
type = Visibility.Type.Group.value,
value = group
value = group,
type = Visibility.Type.Group.value
)
)
context.value.jiraClient.updateComment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ fun MojiraComment.toDomain(
getUpdateAuthorGroups = { if (updateAuthor == null) emptyList() else getGroups(jiraClient, updateAuthor.accountId).fold({ null }, { it }) },
created = created!!.toInstant(),
updated = updated!!.toInstant(),
visibilityType = visibility?.type.toString(),
visibilityType = visibility?.type,
visibilityValue = visibility?.value,
restrict = ::restrictCommentToGroup.partially1(context).partially1(this).partially1("staff"),
update = ::updateCommentBody.partially1(context).partially1(this),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private val log = LoggerFactory.getLogger("PrivacyModule")

class PrivacyModule(
private val message: String,
private val commentMessage: String,
private val commentNote: String,
private val allowedEmailRegexes: List<Regex>,
private val sensitiveTextRegexes: List<Regex>,
Expand Down Expand Up @@ -58,6 +59,9 @@ class PrivacyModule(
}

restrictCommentActions.forEach { it.invoke() }
if (restrictCommentActions.isNotEmpty()) {
addComment(CommentOptions(commentMessage))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class InstantModuleRegistry(config: Config) : ModuleRegistry<CloudIssue>(config)
Arisa.Modules.Privacy,
PrivacyModule(
config[Arisa.Modules.Privacy.message],
config[Arisa.Modules.Privacy.commentMessage],
config[Arisa.Modules.Privacy.commentNote],
config[Arisa.Modules.Privacy.allowedEmailRegexes].map(String::toRegex),
config[Arisa.Modules.Privacy.sensitiveTextRegexes].map(String::toRegex),
Expand Down
Loading