summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/credo/check/consistency/file_location.ex166
-rw-r--r--lib/mix/tasks/pleroma/user.ex6
-rw-r--r--lib/pleroma/user.ex12
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex4
-rw-r--r--lib/pleroma/web/activity_pub/side_effects.ex2
-rw-r--r--lib/pleroma/web/activity_pub/views/user_view.ex2
-rw-r--r--lib/pleroma/web/admin_api/views/account_view.ex2
-rw-r--r--lib/pleroma/web/api_spec/schemas/chat.ex2
-rw-r--r--lib/pleroma/web/api_spec/schemas/status.ex2
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/account_controller.ex2
-rw-r--r--lib/pleroma/web/mastodon_api/views/account_view.ex2
11 files changed, 18 insertions, 184 deletions
diff --git a/lib/credo/check/consistency/file_location.ex b/lib/credo/check/consistency/file_location.ex
deleted file mode 100644
index 500983608..000000000
--- a/lib/credo/check/consistency/file_location.ex
+++ /dev/null
@@ -1,166 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Originally taken from
-# https://github.com/VeryBigThings/elixir_common/blob/master/lib/vbt/credo/check/consistency/file_location.ex
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Credo.Check.Consistency.FileLocation do
- @moduledoc false
-
- # credo:disable-for-this-file Credo.Check.Readability.Specs
-
- @checkdoc """
- File location should follow the namespace hierarchy of the module it defines.
-
- Examples:
-
- - `lib/my_system.ex` should define the `MySystem` module
- - `lib/my_system/accounts.ex` should define the `MySystem.Accounts` module
- """
- @explanation [warning: @checkdoc]
-
- @special_namespaces [
- "controllers",
- "views",
- "operations",
- "channels"
- ]
-
- # `use Credo.Check` required that module attributes are already defined, so we need
- # to place these attributes
- # before use/alias expressions.
- # credo:disable-for-next-line VBT.Credo.Check.Consistency.ModuleLayout
- use Credo.Check, category: :warning, base_priority: :high
-
- alias Credo.Code
-
- def run(source_file, params \\ []) do
- case verify(source_file, params) do
- :ok ->
- []
-
- {:error, module, expected_file} ->
- error(IssueMeta.for(source_file, params), module, expected_file)
- end
- end
-
- defp verify(source_file, params) do
- source_file.filename
- |> Path.relative_to_cwd()
- |> verify(Code.ast(source_file), params)
- end
-
- @doc false
- def verify(relative_path, ast, params) do
- if verify_path?(relative_path, params),
- do: ast |> main_module() |> verify_module(relative_path, params),
- else: :ok
- end
-
- defp verify_path?(relative_path, params) do
- case Path.split(relative_path) do
- ["lib" | _] -> not exclude?(relative_path, params)
- ["test", "support" | _] -> false
- ["test", "test_helper.exs"] -> false
- ["test" | _] -> not exclude?(relative_path, params)
- _ -> false
- end
- end
-
- defp exclude?(relative_path, params) do
- params
- |> Keyword.get(:exclude, [])
- |> Enum.any?(&String.starts_with?(relative_path, &1))
- end
-
- defp main_module(ast) do
- {_ast, modules} = Macro.prewalk(ast, [], &traverse/2)
- Enum.at(modules, -1)
- end
-
- defp traverse({:defmodule, _meta, args}, modules) do
- [{:__aliases__, _, name_parts}, _module_body] = args
- {args, [Module.concat(name_parts) | modules]}
- end
-
- defp traverse(ast, state), do: {ast, state}
-
- # empty file - shouldn't really happen, but we'll let it through
- defp verify_module(nil, _relative_path, _params), do: :ok
-
- defp verify_module(main_module, relative_path, params) do
- parsed_path = parsed_path(relative_path, params)
-
- expected_file =
- expected_file_base(parsed_path.root, main_module) <>
- Path.extname(parsed_path.allowed)
-
- cond do
- expected_file == parsed_path.allowed ->
- :ok
-
- special_namespaces?(parsed_path.allowed) ->
- original_path = parsed_path.allowed
-
- namespace =
- Enum.find(@special_namespaces, original_path, fn namespace ->
- String.contains?(original_path, namespace)
- end)
-
- allowed = String.replace(original_path, "/" <> namespace, "")
-
- if expected_file == allowed,
- do: :ok,
- else: {:error, main_module, expected_file}
-
- true ->
- {:error, main_module, expected_file}
- end
- end
-
- defp special_namespaces?(path), do: String.contains?(path, @special_namespaces)
-
- defp parsed_path(relative_path, params) do
- parts = Path.split(relative_path)
-
- allowed =
- Keyword.get(params, :ignore_folder_namespace, %{})
- |> Stream.flat_map(fn {root, folders} -> Enum.map(folders, &Path.join([root, &1])) end)
- |> Stream.map(&Path.split/1)
- |> Enum.find(&List.starts_with?(parts, &1))
- |> case do
- nil ->
- relative_path
-
- ignore_parts ->
- Stream.drop(ignore_parts, -1)
- |> Enum.concat(Stream.drop(parts, length(ignore_parts)))
- |> Path.join()
- end
-
- %{root: hd(parts), allowed: allowed}
- end
-
- defp expected_file_base(root_folder, module) do
- {parent_namespace, module_name} = module |> Module.split() |> Enum.split(-1)
-
- relative_path =
- if parent_namespace == [],
- do: "",
- else: parent_namespace |> Module.concat() |> Macro.underscore()
-
- file_name = module_name |> Module.concat() |> Macro.underscore()
-
- Path.join([root_folder, relative_path, file_name])
- end
-
- defp error(issue_meta, module, expected_file) do
- format_issue(issue_meta,
- message:
- "Mismatch between file name and main module #{inspect(module)}. " <>
- "Expected file path to be #{expected_file}. " <>
- "Either move the file or rename the module.",
- line_no: 1
- )
- end
-end
diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex
index e06262804..a8d251411 100644
--- a/lib/mix/tasks/pleroma/user.ex
+++ b/lib/mix/tasks/pleroma/user.ex
@@ -419,7 +419,7 @@ defmodule Mix.Tasks.Pleroma.User do
|> Enum.each(fn user ->
shell_info(
"#{user.nickname} moderator: #{user.is_moderator}, admin: #{user.is_admin}, locked: #{
- user.locked
+ user.is_locked
}, deactivated: #{user.deactivated}"
)
end)
@@ -447,10 +447,10 @@ defmodule Mix.Tasks.Pleroma.User do
defp set_locked(user, value) do
{:ok, user} =
user
- |> Changeset.change(%{locked: value})
+ |> Changeset.change(%{is_locked: value})
|> User.update_and_set_cache()
- shell_info("Locked status of #{user.nickname}: #{user.locked}")
+ shell_info("Locked status of #{user.nickname}: #{user.is_locked}")
user
end
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 09ea80793..87c8bfbd1 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -107,7 +107,7 @@ defmodule Pleroma.User do
field(:note_count, :integer, default: 0)
field(:follower_count, :integer, default: 0)
field(:following_count, :integer, default: 0)
- field(:locked, :boolean, default: false)
+ field(:is_locked, :boolean, default: false)
field(:confirmation_pending, :boolean, default: false)
field(:password_reset_pending, :boolean, default: false)
field(:approval_pending, :boolean, default: false)
@@ -436,7 +436,7 @@ defmodule Pleroma.User do
:avatar,
:ap_enabled,
:banner,
- :locked,
+ :is_locked,
:last_refreshed_at,
:uri,
:follower_address,
@@ -479,7 +479,7 @@ defmodule Pleroma.User do
:public_key,
:inbox,
:shared_inbox,
- :locked,
+ :is_locked,
:no_rich_text,
:default_scope,
:banner,
@@ -847,7 +847,7 @@ defmodule Pleroma.User do
@spec maybe_direct_follow(User.t(), User.t()) :: {:ok, User.t()} | {:error, String.t()}
# "Locked" (self-locked) users demand explicit authorization of follow requests
- def maybe_direct_follow(%User{} = follower, %User{local: true, locked: true} = followed) do
+ def maybe_direct_follow(%User{} = follower, %User{local: true, is_locked: true} = followed) do
follow(follower, followed, :follow_pending)
end
@@ -954,7 +954,7 @@ defmodule Pleroma.User do
end
def locked?(%User{} = user) do
- user.locked || false
+ user.is_locked || false
end
def get_by_id(id) do
@@ -1601,7 +1601,7 @@ defmodule Pleroma.User do
note_count: 0,
follower_count: 0,
following_count: 0,
- locked: false,
+ is_locked: false,
confirmation_pending: false,
password_reset_pending: false,
approval_pending: false,
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index eb44cffec..8022f0402 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -1228,7 +1228,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
{String.trim(name, ":"), url}
end)
- locked = data["manuallyApprovesFollowers"] || false
+ is_locked = data["manuallyApprovesFollowers"] || false
capabilities = data["capabilities"] || %{}
accepts_chat_messages = capabilities["acceptsChatMessages"]
data = Transmogrifier.maybe_fix_user_object(data)
@@ -1257,7 +1257,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
banner: banner,
fields: fields,
emoji: emojis,
- locked: locked,
+ is_locked: is_locked,
discoverable: discoverable,
invisible: invisible,
avatar: avatar,
diff --git a/lib/pleroma/web/activity_pub/side_effects.ex b/lib/pleroma/web/activity_pub/side_effects.ex
index 2eec0ce86..d421ca7af 100644
--- a/lib/pleroma/web/activity_pub/side_effects.ex
+++ b/lib/pleroma/web/activity_pub/side_effects.ex
@@ -102,7 +102,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
%User{} = followed <- User.get_cached_by_ap_id(followed_user),
{_, {:ok, _}, _, _} <-
{:following, User.follow(follower, followed, :follow_pending), follower, followed} do
- if followed.local && !followed.locked do
+ if followed.local && !followed.is_locked do
{:ok, accept_data, _} = Builder.accept(followed, object)
{:ok, _activity, _} = Pipeline.common_pipeline(accept_data, local: true)
end
diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex
index 3a4564912..c6dee61db 100644
--- a/lib/pleroma/web/activity_pub/views/user_view.ex
+++ b/lib/pleroma/web/activity_pub/views/user_view.ex
@@ -101,7 +101,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do
"name" => user.name,
"summary" => user.bio,
"url" => user.ap_id,
- "manuallyApprovesFollowers" => user.locked,
+ "manuallyApprovesFollowers" => user.is_locked,
"publicKey" => %{
"id" => "#{user.ap_id}#main-key",
"owner" => user.ap_id,
diff --git a/lib/pleroma/web/admin_api/views/account_view.ex b/lib/pleroma/web/admin_api/views/account_view.ex
index 9c477feab..bda7ea19c 100644
--- a/lib/pleroma/web/admin_api/views/account_view.ex
+++ b/lib/pleroma/web/admin_api/views/account_view.ex
@@ -39,7 +39,7 @@ defmodule Pleroma.Web.AdminAPI.AccountView do
:fields,
:name,
:nickname,
- :locked,
+ :is_locked,
:no_rich_text,
:default_scope,
:hide_follows,
diff --git a/lib/pleroma/web/api_spec/schemas/chat.ex b/lib/pleroma/web/api_spec/schemas/chat.ex
index b4986b734..65f908e33 100644
--- a/lib/pleroma/web/api_spec/schemas/chat.ex
+++ b/lib/pleroma/web/api_spec/schemas/chat.ex
@@ -50,7 +50,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Chat do
"fields" => []
},
"statuses_count" => 1,
- "locked" => false,
+ "is_locked" => false,
"created_at" => "2020-04-16T13:40:15.000Z",
"display_name" => "lain",
"fields" => [],
diff --git a/lib/pleroma/web/api_spec/schemas/status.ex b/lib/pleroma/web/api_spec/schemas/status.ex
index 947e42890..e6890df2d 100644
--- a/lib/pleroma/web/api_spec/schemas/status.ex
+++ b/lib/pleroma/web/api_spec/schemas/status.ex
@@ -252,7 +252,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
"header" => "http://localhost:4001/images/banner.png",
"header_static" => "http://localhost:4001/images/banner.png",
"id" => "9toJCsKN7SmSf3aj5c",
- "locked" => false,
+ "is_locked" => false,
"note" => "Tester Number 6",
"pleroma" => %{
"background_image" => nil,
diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
index 4f9696d52..97858a93c 100644
--- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
@@ -177,7 +177,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
user_params =
[
:no_rich_text,
- :locked,
:hide_followers_count,
:hide_follows_count,
:hide_followers,
@@ -210,6 +209,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
if bot, do: {:ok, "Service"}, else: {:ok, "Person"}
end)
|> Maps.put_if_present(:actor_type, params[:actor_type])
+ |> Maps.put_if_present(:is_locked, params[:locked])
# What happens here:
#
diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex
index 121ba1693..d54cae732 100644
--- a/lib/pleroma/web/mastodon_api/views/account_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/account_view.ex
@@ -242,7 +242,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
username: username_from_nickname(user.nickname),
acct: user.nickname,
display_name: display_name,
- locked: user.locked,
+ locked: user.is_locked,
created_at: Utils.to_masto_date(user.inserted_at),
followers_count: followers_count,
following_count: following_count,