-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let admins access the management pages, but filter the data by facility.
- Loading branch information
1 parent
8e5fbc6
commit 9acb8d0
Showing
7 changed files
with
78 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,20 @@ | ||
defmodule OpenPantry.Repo do | ||
use Ecto.Repo, otp_app: :open_pantry | ||
use Scrivener, page_size: 10 | ||
|
||
import Ecto.Query, only: [from: 2] | ||
|
||
alias OpenPantry.User | ||
|
||
def filter_facility(query, conn) do | ||
user = Guardian.Plug.current_resource(conn) | ||
case user do | ||
%User{role: :superadmin} -> | ||
query | ||
%User{role: :admin, facility_id: facility_id} when facility_id > 0 -> | ||
from q in query, where: q.facility_id == ^facility_id | ||
_ -> | ||
from q in query, where: is_nil(q.facility_id) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters