-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2bdf2fa
commit f3693bc
Showing
8 changed files
with
67 additions
and
2 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
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,4 @@ | ||
require "message_pb" | ||
require "message_type" | ||
|
||
module Youtube | ||
class Transcript | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module Authenticator | ||
class AdminConstraint | ||
def matches?(request) | ||
session = Session.find_by_id(request.cookie_jar.signed[:session_token]) | ||
|
||
if session | ||
session.user.admin? | ||
else | ||
false | ||
end | ||
end | ||
end | ||
|
||
class UserConstraint | ||
def matches?(request) | ||
session = Session.find_by_id(request.cookie_jar.signed[:session_token]) | ||
|
||
if session | ||
session.user | ||
else | ||
false | ||
end | ||
end | ||
end | ||
|
||
class ForbiddenConstraint | ||
def matches?(request) = false | ||
end | ||
|
||
ROLES = { | ||
admin: AdminConstraint, | ||
user: UserConstraint | ||
} | ||
|
||
def authenticate(role, &) | ||
constraints(constraint_for(role), &) | ||
end | ||
|
||
private | ||
|
||
def constraint_for(role) | ||
ROLES[role.to_sym]&.new || ForbiddenConstraint.new | ||
end | ||
end |
File renamed without changes.