Skip to content

Commit

Permalink
fix permissions for consortium. #432
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Feb 26, 2020
1 parent c5da1da commit b3073b1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ def set_jsonp_format
end

def detect_crawler
#### Crawlers shound't be making queires
#### Crawlers shouldn't be making queires
if request.is_crawler? && params[:query].present?
render json: {}, status: :not_found
end
end


def set_consumer_header
if current_user
response.headers['X-Credential-Username'] = current_user.uid
Expand Down
5 changes: 5 additions & 0 deletions app/models/concerns/authenticable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ def get_payload(uid: nil, user: nil, password: nil)
"client_id" => uid,
"password" => password
})
elsif user.role_name == "ROLE_CONSORTIUM"
payload.merge!({
"provider_id" => uid,
"consortium_id" => uid
})
elsif uid != "admin"
payload.merge!({
"provider_id" => uid
Expand Down
5 changes: 5 additions & 0 deletions spec/concerns/authenticable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@
subject = create(:provider, symbol: "ADMIN", role_name: "ROLE_ADMIN", password_input: "12345")
expect(subject.decode_auth_param(username: subject.symbol, password: "12345")).to eq("uid"=>subject.symbol.downcase, "name"=>subject.name, "email"=>subject.system_email, "role_id"=>"staff_admin")
end

it "consortium" do
subject = create(:provider, role_name: "ROLE_CONSORTIUM", password_input: "12345")
expect(subject.decode_auth_param(username: subject.symbol, password: "12345")).to eq("uid"=>subject.symbol.downcase, "name"=>subject.name, "email"=>subject.system_email, "role_id"=>"provider_admin", "provider_id"=>subject.symbol.downcase, "consortium_id"=>subject.symbol.downcase)
end
end
end

Expand Down

0 comments on commit b3073b1

Please sign in to comment.