mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 14:17:59 +01:00
add forum ability
This commit is contained in:
parent
0d74aa9ab0
commit
a37699338e
7 changed files with 34 additions and 10 deletions
|
@ -1,20 +1,51 @@
|
||||||
defimpl Canada.Can, for: [Atom, Philomena.Users.User] do
|
defimpl Canada.Can, for: [Atom, Philomena.Users.User] do
|
||||||
alias Philomena.Users.User
|
alias Philomena.Users.User
|
||||||
alias Philomena.Images.Image
|
alias Philomena.Images.Image
|
||||||
|
alias Philomena.Forums.Forum
|
||||||
|
alias Philomena.Topics.Topic
|
||||||
|
|
||||||
# Admins can do anything
|
# Admins can do anything
|
||||||
def can?(%User{role: "admin"}, _action, _model), do: true
|
def can?(%User{role: "admin"}, _action, _model), do: true
|
||||||
|
|
||||||
# Users can...
|
#
|
||||||
|
# Moderators can...
|
||||||
|
#
|
||||||
|
|
||||||
|
# View images
|
||||||
|
def can?(%User{role: "moderator"}, :show, %Image{}), do: true
|
||||||
|
|
||||||
|
# View forums
|
||||||
|
def can?(%User{role: "moderator"}, :show, %Forum{access_level: level})
|
||||||
|
when level in ["normal", "assistant", "staff"], do: true
|
||||||
|
def can?(%User{role: "moderator"}, :show, %Topic{hidden_from_users: true}), do: true
|
||||||
|
|
||||||
|
#
|
||||||
|
# Assistants can...
|
||||||
|
#
|
||||||
|
|
||||||
|
# View images
|
||||||
|
def can?(%User{role: "assistant"}, :show, %Image{}), do: true
|
||||||
|
|
||||||
|
# View forums
|
||||||
|
def can?(%User{role: "assistant"}, :show, %Forum{access_level: level})
|
||||||
|
when level in ["normal", "assistant"], do: true
|
||||||
|
def can?(%User{role: "assistant"}, :show, %Topic{hidden_from_users: true}), do: true
|
||||||
|
|
||||||
|
#
|
||||||
|
# Users and anonymous users can...
|
||||||
|
#
|
||||||
|
|
||||||
# View non-deleted images
|
# View non-deleted images
|
||||||
def can?(_user, action, Image)
|
def can?(_user, action, Image)
|
||||||
when action in [:new, :create, :index],
|
when action in [:new, :create, :index],
|
||||||
do: true
|
do: true
|
||||||
|
|
||||||
def can?(_user, :show, %Image{hidden_from_users: true}), do: false
|
|
||||||
def can?(_user, :show, %Image{hidden_from_users: false}), do: true
|
def can?(_user, :show, %Image{hidden_from_users: false}), do: true
|
||||||
|
|
||||||
|
# View forums
|
||||||
|
def can?(_user, :show, %Forum{access_level: "normal"}), do: true
|
||||||
|
def can?(_user, :show, %Topic{hidden_from_users: false}), do: true
|
||||||
|
|
||||||
# Otherwise...
|
# Otherwise...
|
||||||
def can?(_user, _action, _model), do: false
|
def can?(_user, _action, _model), do: false
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,7 +25,6 @@ defmodule PhilomenaWeb do
|
||||||
import PhilomenaWeb.Gettext
|
import PhilomenaWeb.Gettext
|
||||||
import Canary.Plugs
|
import Canary.Plugs
|
||||||
alias PhilomenaWeb.Router.Helpers, as: Routes
|
alias PhilomenaWeb.Router.Helpers, as: Routes
|
||||||
alias PhilomenaWeb.Plugs.ImageFilter
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,6 @@ defmodule PhilomenaWeb.ActivityController do
|
||||||
alias Philomena.Repo
|
alias Philomena.Repo
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
plug ImageFilter
|
|
||||||
|
|
||||||
def index(conn, _params) do
|
def index(conn, _params) do
|
||||||
user = conn.assigns.current_user
|
user = conn.assigns.current_user
|
||||||
filter = conn.assigns.compiled_filter
|
filter = conn.assigns.compiled_filter
|
||||||
|
|
|
@ -5,7 +5,6 @@ defmodule PhilomenaWeb.ImageController do
|
||||||
alias Philomena.Repo
|
alias Philomena.Repo
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
plug ImageFilter
|
|
||||||
plug :load_and_authorize_resource, model: Image, only: :show, preload: [:tags, :user]
|
plug :load_and_authorize_resource, model: Image, only: :show, preload: [:tags, :user]
|
||||||
|
|
||||||
def index(conn, _params) do
|
def index(conn, _params) do
|
||||||
|
|
|
@ -6,8 +6,6 @@ defmodule PhilomenaWeb.SearchController do
|
||||||
|
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
plug ImageFilter
|
|
||||||
|
|
||||||
def index(conn, params) do
|
def index(conn, params) do
|
||||||
filter = conn.assigns[:compiled_filter]
|
filter = conn.assigns[:compiled_filter]
|
||||||
user = conn |> Plug.current_user()
|
user = conn |> Plug.current_user()
|
||||||
|
|
|
@ -4,8 +4,6 @@ defmodule PhilomenaWeb.TagController do
|
||||||
alias Philomena.{Images.Image, Tags, Tags.Tag}
|
alias Philomena.{Images.Image, Tags, Tags.Tag}
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
plug ImageFilter
|
|
||||||
|
|
||||||
def index(conn, params) do
|
def index(conn, params) do
|
||||||
{:ok, query} = Tags.Query.compile(params["tq"] || "*")
|
{:ok, query} = Tags.Query.compile(params["tq"] || "*")
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ defmodule PhilomenaWeb.Router do
|
||||||
plug :fetch_flash
|
plug :fetch_flash
|
||||||
plug :protect_from_forgery
|
plug :protect_from_forgery
|
||||||
plug :put_secure_browser_headers
|
plug :put_secure_browser_headers
|
||||||
|
plug PhilomenaWeb.Plugs.ImageFilter
|
||||||
end
|
end
|
||||||
|
|
||||||
pipeline :api do
|
pipeline :api do
|
||||||
|
|
Loading…
Reference in a new issue