def remote_or_auth_active?(%User{} = user), do: !user.local || auth_active?(user)
+ def visible_for?(%User{} = user, for_user \\ nil) do
+ User.remote_or_auth_active?(user) || (for_user && for_user.id == user.id) ||
+ User.superuser?(for_user)
+ end
+
+ def superuser?(nil), do: false
def superuser?(%User{} = user), do: user.info && User.Info.superuser?(user.info)
def avatar_url(user) do
end
def render("account.json", %{user: user} = opts) do
- for_user = opts[:for]
-
- allow_render =
- User.remote_or_auth_active?(user) ||
- (for_user && (for_user.id == user.id || User.superuser?(for_user)))
-
- if allow_render do
- render("valid_account.json", opts)
- else
- render("invalid_account.json", opts)
- end
+ if User.visible_for?(user, opts[:for]),
+ do: render("valid_account.json", opts),
+ else: render("invalid_account.json", opts)
end
def render("invalid_account.json", _opts) do
end
def render("user.json", %{user: user = %User{}} = assigns) do
- for_user = assigns[:for]
-
- allow_render =
- User.remote_or_auth_active?(user) ||
- (for_user && (for_user.id == user.id || User.superuser?(for_user)))
-
- if allow_render do
- render("valid_user.json", assigns)
- else
- render("invalid_user.json", assigns)
- end
+ if User.visible_for?(user, assigns[:for]),
+ do: render("valid_user.json", assigns),
+ else: render("invalid_user.json", assigns)
end
def render("invalid_user.json", _assigns) do