Merge remote-tracking branch 'pleroma/develop' into feature/disable-account
[akkoma] / lib / pleroma / web / controller_helper.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ControllerHelper do
6 use Pleroma.Web, :controller
7
8 # As in MastoAPI, per https://api.rubyonrails.org/classes/ActiveModel/Type/Boolean.html
9 @falsy_param_values [false, 0, "0", "f", "F", "false", "FALSE", "off", "OFF"]
10 def truthy_param?(blank_value) when blank_value in [nil, ""], do: nil
11 def truthy_param?(value), do: value not in @falsy_param_values
12
13 def oauth_scopes(params, default) do
14 # Note: `scopes` is used by Mastodon — supporting it but sticking to
15 # OAuth's standard `scope` wherever we control it
16 Pleroma.Web.OAuth.parse_scopes(params["scope"] || params["scopes"], default)
17 end
18
19 def json_response(conn, status, json) do
20 conn
21 |> put_status(status)
22 |> json(json)
23 end
24 end