Add mix task for bulk [un]confirming the local instance users
This commit is contained in:
parent
23ca5f75af
commit
75b6fef25d
|
@ -224,9 +224,10 @@
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
- `--locked`/`--no-locked` - whether the user should be locked
|
- `--admin`/`--no-admin` - the user account admin status
|
||||||
- `--moderator`/`--no-moderator` - whether the user should be a moderator
|
- `--confirmed`/`--no-confirmed` - the user account confirmation status
|
||||||
- `--admin`/`--no-admin` - whether the user should be an admin
|
- `--locked`/`--no-locked` - the user account locked status
|
||||||
|
- `--moderator`/`--no-moderator` - the user account moderator status
|
||||||
|
|
||||||
## Add tags to a user
|
## Add tags to a user
|
||||||
|
|
||||||
|
@ -271,3 +272,33 @@
|
||||||
```sh
|
```sh
|
||||||
mix pleroma.user toggle_confirmed <nickname>
|
mix pleroma.user toggle_confirmed <nickname>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Set confirmation status for all regular active users
|
||||||
|
*Admins and moderators are excluded*
|
||||||
|
|
||||||
|
=== "OTP"
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./bin/pleroma_ctl user confirm_all
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "From Source"
|
||||||
|
|
||||||
|
```sh
|
||||||
|
mix pleroma.user confirm_all
|
||||||
|
```
|
||||||
|
|
||||||
|
## Revoke confirmation status for all regular active users
|
||||||
|
*Admins and moderators are excluded*
|
||||||
|
|
||||||
|
=== "OTP"
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./bin/pleroma_ctl user unconfirm_all
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "From Source"
|
||||||
|
|
||||||
|
```sh
|
||||||
|
mix pleroma.user unconfirm_all
|
||||||
|
```
|
||||||
|
|
|
@ -196,17 +196,24 @@ def run(["set", nickname | rest]) do
|
||||||
OptionParser.parse(
|
OptionParser.parse(
|
||||||
rest,
|
rest,
|
||||||
strict: [
|
strict: [
|
||||||
moderator: :boolean,
|
|
||||||
admin: :boolean,
|
admin: :boolean,
|
||||||
locked: :boolean
|
confirmed: :boolean,
|
||||||
|
locked: :boolean,
|
||||||
|
moderator: :boolean
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
||||||
user =
|
user =
|
||||||
case Keyword.get(options, :moderator) do
|
case Keyword.get(options, :admin) do
|
||||||
nil -> user
|
nil -> user
|
||||||
value -> set_moderator(user, value)
|
value -> set_admin(user, value)
|
||||||
|
end
|
||||||
|
|
||||||
|
user =
|
||||||
|
case Keyword.get(options, :confirmed) do
|
||||||
|
nil -> user
|
||||||
|
value -> set_confirmed(user, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
user =
|
user =
|
||||||
|
@ -216,9 +223,9 @@ def run(["set", nickname | rest]) do
|
||||||
end
|
end
|
||||||
|
|
||||||
_user =
|
_user =
|
||||||
case Keyword.get(options, :admin) do
|
case Keyword.get(options, :moderator) do
|
||||||
nil -> user
|
nil -> user
|
||||||
value -> set_admin(user, value)
|
value -> set_moderator(user, value)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -353,6 +360,42 @@ def run(["toggle_confirmed", nickname]) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def run(["confirm_all"]) do
|
||||||
|
start_pleroma()
|
||||||
|
|
||||||
|
Pleroma.User.Query.build(%{
|
||||||
|
local: true,
|
||||||
|
deactivated: false,
|
||||||
|
is_moderator: false,
|
||||||
|
is_admin: false,
|
||||||
|
invisible: false
|
||||||
|
})
|
||||||
|
|> Pleroma.RepoStreamer.chunk_stream(500)
|
||||||
|
|> Stream.each(fn users ->
|
||||||
|
users
|
||||||
|
|> Enum.each(fn user -> User.need_confirmation(user, false) end)
|
||||||
|
end)
|
||||||
|
|> Stream.run()
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(["unconfirm_all"]) do
|
||||||
|
start_pleroma()
|
||||||
|
|
||||||
|
Pleroma.User.Query.build(%{
|
||||||
|
local: true,
|
||||||
|
deactivated: false,
|
||||||
|
is_moderator: false,
|
||||||
|
is_admin: false,
|
||||||
|
invisible: false
|
||||||
|
})
|
||||||
|
|> Pleroma.RepoStreamer.chunk_stream(500)
|
||||||
|
|> Stream.each(fn users ->
|
||||||
|
users
|
||||||
|
|> Enum.each(fn user -> User.need_confirmation(user, true) end)
|
||||||
|
end)
|
||||||
|
|> Stream.run()
|
||||||
|
end
|
||||||
|
|
||||||
def run(["sign_out", nickname]) do
|
def run(["sign_out", nickname]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
|
@ -410,4 +453,15 @@ defp set_locked(user, value) do
|
||||||
shell_info("Locked status of #{user.nickname}: #{user.locked}")
|
shell_info("Locked status of #{user.nickname}: #{user.locked}")
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp set_confirmed(user, value) do
|
||||||
|
{:ok, user} =
|
||||||
|
case value do
|
||||||
|
true -> User.need_confirmation(user, false)
|
||||||
|
false -> User.need_confirmation(user, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
shell_info("Confirmation pending status of #{user.nickname}: #{user.confirmation_pending}")
|
||||||
|
user
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2123,6 +2123,13 @@ def toggle_confirmation(users) do
|
||||||
Enum.map(users, &toggle_confirmation/1)
|
Enum.map(users, &toggle_confirmation/1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec need_confirmation(User.t(), boolean()) :: {:ok, User.t()} | {:error, Changeset.t()}
|
||||||
|
def need_confirmation(%User{} = user, bool) do
|
||||||
|
user
|
||||||
|
|> confirmation_changeset(need_confirmation: bool)
|
||||||
|
|> update_and_set_cache()
|
||||||
|
end
|
||||||
|
|
||||||
def get_mascot(%{mascot: %{} = mascot}) when not is_nil(mascot) do
|
def get_mascot(%{mascot: %{} = mascot}) when not is_nil(mascot) do
|
||||||
mascot
|
mascot
|
||||||
end
|
end
|
||||||
|
|
|
@ -107,12 +107,12 @@ defp compose_query({:tags, tags}, query) when is_list(tags) and length(tags) > 0
|
||||||
where(query, [u], fragment("? && ?", u.tags, ^tags))
|
where(query, [u], fragment("? && ?", u.tags, ^tags))
|
||||||
end
|
end
|
||||||
|
|
||||||
defp compose_query({:is_admin, _}, query) do
|
defp compose_query({:is_admin, bool}, query) do
|
||||||
where(query, [u], u.is_admin)
|
where(query, [u], u.is_admin == ^bool)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp compose_query({:is_moderator, _}, query) do
|
defp compose_query({:is_moderator, bool}, query) do
|
||||||
where(query, [u], u.is_moderator)
|
where(query, [u], u.is_moderator == ^bool)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp compose_query({:super_users, _}, query) do
|
defp compose_query({:super_users, _}, query) do
|
||||||
|
|
Loading…
Reference in New Issue