forked from YokaiRick/akkoma
moderation log: fix improperly migrated data
Some of the actions used to have a user map as a subject, which was then changed to an array of user maps. However instead of migrating old data there was just a hack to transform it every time, moreover this hack didn't include all possible actions, which resulted in crashes. This commit fixes the crashes by introducing a proper database migration for old data. Closes #1606
This commit is contained in:
parent
474ef512df
commit
6cf1958b02
2 changed files with 9 additions and 76 deletions
|
@ -387,24 +387,6 @@ def get_log_entry_message(%ModerationLog{
|
||||||
"@#{actor_nickname} created users: #{users_to_nicknames_string(subjects)}"
|
"@#{actor_nickname} created users: #{users_to_nicknames_string(subjects)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec get_log_entry_message(ModerationLog) :: String.t()
|
|
||||||
def get_log_entry_message(%ModerationLog{
|
|
||||||
data: %{
|
|
||||||
"actor" => %{"nickname" => actor_nickname},
|
|
||||||
"action" => "activate",
|
|
||||||
"subject" => user
|
|
||||||
}
|
|
||||||
})
|
|
||||||
when is_map(user) do
|
|
||||||
get_log_entry_message(%ModerationLog{
|
|
||||||
data: %{
|
|
||||||
"actor" => %{"nickname" => actor_nickname},
|
|
||||||
"action" => "activate",
|
|
||||||
"subject" => [user]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec get_log_entry_message(ModerationLog) :: String.t()
|
@spec get_log_entry_message(ModerationLog) :: String.t()
|
||||||
def get_log_entry_message(%ModerationLog{
|
def get_log_entry_message(%ModerationLog{
|
||||||
data: %{
|
data: %{
|
||||||
|
@ -416,24 +398,6 @@ def get_log_entry_message(%ModerationLog{
|
||||||
"@#{actor_nickname} activated users: #{users_to_nicknames_string(users)}"
|
"@#{actor_nickname} activated users: #{users_to_nicknames_string(users)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec get_log_entry_message(ModerationLog) :: String.t()
|
|
||||||
def get_log_entry_message(%ModerationLog{
|
|
||||||
data: %{
|
|
||||||
"actor" => %{"nickname" => actor_nickname},
|
|
||||||
"action" => "deactivate",
|
|
||||||
"subject" => user
|
|
||||||
}
|
|
||||||
})
|
|
||||||
when is_map(user) do
|
|
||||||
get_log_entry_message(%ModerationLog{
|
|
||||||
data: %{
|
|
||||||
"actor" => %{"nickname" => actor_nickname},
|
|
||||||
"action" => "deactivate",
|
|
||||||
"subject" => [user]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec get_log_entry_message(ModerationLog) :: String.t()
|
@spec get_log_entry_message(ModerationLog) :: String.t()
|
||||||
def get_log_entry_message(%ModerationLog{
|
def get_log_entry_message(%ModerationLog{
|
||||||
data: %{
|
data: %{
|
||||||
|
@ -473,26 +437,6 @@ def get_log_entry_message(%ModerationLog{
|
||||||
"@#{actor_nickname} removed tags: #{tags_string} from users: #{nicknames_to_string(nicknames)}"
|
"@#{actor_nickname} removed tags: #{tags_string} from users: #{nicknames_to_string(nicknames)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec get_log_entry_message(ModerationLog) :: String.t()
|
|
||||||
def get_log_entry_message(%ModerationLog{
|
|
||||||
data: %{
|
|
||||||
"actor" => %{"nickname" => actor_nickname},
|
|
||||||
"action" => "grant",
|
|
||||||
"subject" => user,
|
|
||||||
"permission" => permission
|
|
||||||
}
|
|
||||||
})
|
|
||||||
when is_map(user) do
|
|
||||||
get_log_entry_message(%ModerationLog{
|
|
||||||
data: %{
|
|
||||||
"actor" => %{"nickname" => actor_nickname},
|
|
||||||
"action" => "grant",
|
|
||||||
"subject" => [user],
|
|
||||||
"permission" => permission
|
|
||||||
}
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec get_log_entry_message(ModerationLog) :: String.t()
|
@spec get_log_entry_message(ModerationLog) :: String.t()
|
||||||
def get_log_entry_message(%ModerationLog{
|
def get_log_entry_message(%ModerationLog{
|
||||||
data: %{
|
data: %{
|
||||||
|
@ -505,26 +449,6 @@ def get_log_entry_message(%ModerationLog{
|
||||||
"@#{actor_nickname} made #{users_to_nicknames_string(users)} #{permission}"
|
"@#{actor_nickname} made #{users_to_nicknames_string(users)} #{permission}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec get_log_entry_message(ModerationLog) :: String.t()
|
|
||||||
def get_log_entry_message(%ModerationLog{
|
|
||||||
data: %{
|
|
||||||
"actor" => %{"nickname" => actor_nickname},
|
|
||||||
"action" => "revoke",
|
|
||||||
"subject" => user,
|
|
||||||
"permission" => permission
|
|
||||||
}
|
|
||||||
})
|
|
||||||
when is_map(user) do
|
|
||||||
get_log_entry_message(%ModerationLog{
|
|
||||||
data: %{
|
|
||||||
"actor" => %{"nickname" => actor_nickname},
|
|
||||||
"action" => "revoke",
|
|
||||||
"subject" => [user],
|
|
||||||
"permission" => permission
|
|
||||||
}
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec get_log_entry_message(ModerationLog) :: String.t()
|
@spec get_log_entry_message(ModerationLog) :: String.t()
|
||||||
def get_log_entry_message(%ModerationLog{
|
def get_log_entry_message(%ModerationLog{
|
||||||
data: %{
|
data: %{
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
defmodule Pleroma.Repo.Migrations.FixModerationLogSubjects do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
execute(
|
||||||
|
"update moderation_log set data = safe_jsonb_set(data, '{subject}', safe_jsonb_set('[]'::jsonb, '{0}', data->'subject')) where jsonb_typeof(data->'subject') != 'array' and data->>'action' = ANY('{revoke,grant,activate,deactivate,delete}');"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue