-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite grack usage of origin url and tests [#76]
- Loading branch information
Showing
2 changed files
with
33 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,11 +29,15 @@ def halt(message) | |
def call(env) | ||
@env = env | ||
|
||
path_info = env["PATH_INFO"] | ||
# We want to do auth things first | ||
@req = Rack::Request.new(env) | ||
|
||
values = {} | ||
return unauthorized unless auth.provided? | ||
return bad_request unless auth.basic? | ||
|
||
# /courses/1/labs/2 => {:courses=>1, :labs=>2} | ||
path_info = env["PATH_INFO"] | ||
values = {} | ||
# /courses/1/lab_groups/3/labs/2 => {:courses=>1, :labs=>2, :lab_groups=>3} | ||
path_info.scan(%r{\w+/\d+}) do |match| | ||
res = match.split("/") | ||
values.merge!(res.first.to_sym => res.last.to_i) | ||
|
@@ -51,26 +55,33 @@ def call(env) | |
return bad_request | ||
end | ||
|
||
# TODO: fix query, it should not pick first, rather based on credentials | ||
unless lhg = lab.lab_has_groups.first | ||
lab_group = LabGroup. | ||
where("lab_groups.given_course_id = ?", values[:courses]). | ||
find_by_number(values[:lab_groups]) | ||
|
||
unless lab_group | ||
halt("Lab group not found") | ||
return bad_request | ||
end | ||
|
||
# TODO: Fix most inefficient query ever | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jesjos
Member
|
||
lab_has_groups = lab_group.lab_has_groups & lab.lab_has_groups | ||
lab_has_group = lab_has_groups.first | ||
|
||
unless lab_has_group | ||
halt("Lab has group not found") | ||
return bad_request | ||
end | ||
|
||
unless repository = lhg.repository | ||
unless repository = lab_has_group.repository | ||
halt("Repository not found") | ||
return bad_request | ||
end | ||
|
||
env["PATH_INFO"] = path_info.gsub(/^.*\.git/, "/" + repository.hashed_path + ".git") | ||
|
||
@req = Rack::Request.new(env) | ||
|
||
return unauthorized unless auth.provided? | ||
return bad_request unless auth.basic? | ||
return unauthorized unless authorized?(lhg) | ||
return unauthorized unless authorized?(lab_has_group) | ||
|
||
# env['REMOTE_USER'] = auth.username | ||
@app.call(env) | ||
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
Hur enkelt är det att göra en riktig databas join nedan? Ni som kan rails, @oleander @jesjos