Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #2969 - remove all legacy api code in UI controllers + fixes #2985 remove #as_json + fixes #2986 remove #show #855

Closed
wants to merge 4 commits into from

Conversation

isratrade
Copy link
Member

I left the json code in the following controllers as they don't appear in the API code

  • StatisticsController
  • TasksController

Also, the json code used by the UI was of course not removed

@@ -8,10 +8,7 @@ def index
autosign = []
error e
end
respond_to do |format|
format.html { @autosign = autosign.paginate :page => params[:page], :per_page => 20 }
format.json {render :json => autosign }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think we have that over the API, can you add a ticket to add that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@ohadlevy
Copy link
Member

two minor comments

  1. please remove the routes where you removed the show action
  2. should we remove the as_json from the model as well?

@isratrade
Copy link
Member Author

@ohadlevy, yes I will also remove the as_json from the models as well. My assumption is these were only used for the API. I will check if any changes after the ajax dropdown lists.

@isratrade
Copy link
Member Author

@ohadlevy, re-committed.

  1. reverted autosign_controller to include json
  2. removed #as_json methods
  3. removed #show methods and routes when not needed

@isratrade
Copy link
Member Author

@domcleal, @ohadlevy, if I split out fixes #2985 or #2986 into separate PR's, all the json tests removed in fixes #2969 will fail.

@ohadlevy
Copy link
Member

@isratrade it seems to be failing, can you have a look?

@@ -1,12 +1,16 @@
object @host

attributes :name, :id, :ip, :environment, :last_report, :updated_at, :created_at, :mac,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:environment was moved below to a child node, since it caused an error "no method key?", I assume since the as_json was removed from the Environment model.

@isratrade
Copy link
Member Author

I added issue #3006 - Add to API v1 /api/hosts/disabled as /hosts/disabled with json response no longer works

@@ -6,23 +6,6 @@ class ComputeResourcesControllerTest < ActionController::TestCase
@your_compute_resource = compute_resources(:yourcompute)
end

test "should not get index when not permitted" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should keep this test, but remove the JSON bit of the request

@domcleal
Copy link
Contributor

domcleal commented Sep 2, 2013

This will wait for Greg's #858 as there's going to be a very small conflict on the reports model as_json I think, it'll be merged shortly.

@domcleal
Copy link
Contributor

domcleal commented Sep 6, 2013

Could you rebase this please @isratrade? Thanks!

@isratrade
Copy link
Member Author

@domcleal, rebased

@domcleal
Copy link
Contributor

domcleal commented Sep 8, 2013

@isratrade did you see the comments about tests? Some of them could be quite useful if made non-JSON specific.

@isratrade
Copy link
Member Author

@domcleal, @ohadlevy, re-committed with fixes in last commit that I will squash after your review.
Btw, I didn't remove the as_json in report.rb or log.rb as I know @GregSutcliffe's recent PR modified these. Should they be removed and re-constructed in api/v1

@domcleal
Copy link
Contributor

domcleal commented Sep 9, 2013

yes, I think they should be removed

@isratrade
Copy link
Member Author

rebased and recommited with as_json from log.rb and report.rb removed

@ohadlevy
Copy link
Member

ohadlevy commented Sep 9, 2013

@isratrade I'm getting two errors:

inished tests in 109.746279s, 6.3328 tests/s, 11.6268 assertions/s.

  1) Failure:
Api::V1::HostsControllerTest#test_0019_if only authorize_login_delegation is set, REMOTE_USER should be
        ignored for API requests [/home/olevy/git/foreman/test/functional/api/v1/hosts_controller_test.rb:170]:
Expected response to be a <401>, but was <200>

  2) Failure:
Api::V1::HostsControllerTest#test_0020_if both authorize_login_delegation{,_api} are unset,
        REMOTE_USER should ignored in all cases [/home/olevy/git/foreman/test/functional/api/v1/hosts_controller_test.rb:184]:
Expected response to be a <401>, but was <200>

@GregSutcliffe
Copy link
Member

this looks good from the Reports api viewpoint now, thanks @isratrade

@ohadlevy
Copy link
Member

ohadlevy commented Sep 9, 2013

I think we need to remove the api handling from the application_controller
as well.

@isratrade
Copy link
Member Author

@ohadlevy, @domcleal, recommitted

  • added separate commit for deprecation notice
  • removed json test from settings_controller_test
  • modified test_audit_comment test in conflig_templates_controller_test

@isratrade
Copy link
Member Author

+1

@domcleal
Copy link
Contributor

domcleal commented Sep 9, 2013

@isratrade this needs a rebase now, because of the change to the hosts API rabl, thanks!

@@ -1,6 +1,6 @@
object @host

attributes :name, :id, :ip, :environment_id, :environment, :last_report, :updated_at, :created_at, :mac,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@domcleal, rebased with conflicts resolved in hosts#show json. :environment was removed since there is no as_json method. It was replaced by child :environment in line #19 to keep consistent with UI controller output for v1.

@domcleal
Copy link
Contributor

I consider the "warning" in 62e6c84 less of a warning and more of a final error.. could we just use a normal error response?

@isratrade
Copy link
Member Author

@domcleal, I'm not sure this is what you wanted but the response for json calls to a UI controller is

{
    "message": "You must add /api/ to the beginning on your URI such as 0.0.0.0:3000/api/environments"
}

I need to create the json manually, since I'm in the UI ApplicationController controller and don't have access to the render_error method in Api::BaseController. However, render_error just calls one of several templates in api/v1/errors (or v2) that just have a simple response with node(:message). I also added to the log an error message with the real exception ActionView::MissingTemplate that I rescued from

@isratrade
Copy link
Member Author

recommitted. Returns status 400 and includes actual exception (ActionView::MissingTemplate) in logger.error in addition to deprecation message

@domcleal
Copy link
Contributor

Thanks @isratrade, that's much better. Unfortunately I can't get it to work, do you see this bug, or what's happening?

$ git co -
HEAD is now at f5ec783... fixes #2969 - add deprecation response for api calls to UI routes
$ curl -s -u admin:changeme -H 'Accept: application/json' "http://0.0.0.0:3000/hosts/iridium.redhat.com"
 $ 

(a single space in the output)

Started GET "/hosts/iridium.redhat.com" for 127.0.0.1 at 2013-09-10 16:45:27 +0100
Processing by HostsController#show as JSON
  Parameters: {"id"=>"iridium.redhat.com"}
  User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."login" = 'admin' LIMIT 1
  AuthSource Load (0.1ms)  SELECT "auth_sources".* FROM "auth_sources" WHERE "auth_sources"."id" = 1 LIMIT 1
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE (login='admin') LIMIT 1
Authenticated user Admin User against INTERNAL authentication source
  User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."login" = 'admin' ORDER BY firstname LIMIT 1
Setting current user thread-local variable to admin
   (0.0ms)  begin transaction
   (0.2ms)  UPDATE "users" SET "last_login_on" = '2013-09-10 15:45:29.651730', "updated_at" = '2013-09-10 15:45:29.652912' WHERE "users"."id" = 1
   (33.3ms)  commit transaction
  Role Load (0.1ms)  SELECT "roles".* FROM "roles" WHERE "roles"."name" = 'Anonymous' LIMIT 1
  Role Exists (0.1ms)  SELECT 1 AS one FROM "roles" INNER JOIN "user_roles" ON "roles"."id" = "user_roles"."role_id" WHERE "user_roles"."user_id" = 1 AND "roles"."id" = 8 LIMIT 1
Setting current user thread-local variable to admin
Setting current user thread-local variable to nil
  User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."login" = 'admin' LIMIT 1
Authorized user admin(Admin User)
Setting current user thread-local variable to admin
  Host::Base Load (0.1ms)  SELECT "hosts".* FROM "hosts" WHERE "hosts"."name" = 'iridium.redhat.com' LIMIT 1
Completed 406 Not Acceptable in 389ms (ActiveRecord: 35.7ms)

@isratrade
Copy link
Member Author

@domcleal, I'm also getting 406 for /hosts or hosts/:id and not sure why. I was testing with /domains and /environments.

There's another issue that came up. I can't rescue_from ActionController::RoutingError
rails/rails#671
unless I use a catch-all route and we didn't want to do this since it messes up engine routes.

So for show actions such as domains/12, I get a routing error because :show was removed from routes.rb when it's not used.

I don't have a good solution, since there are some places in the UI that uses JSON, so we can't capture all JSON requests.

@ohadlevy, any ideas

@lzap
Copy link
Member

lzap commented Sep 10, 2013

This pull request is considered as blocker for Foreman 1.3 release.

@isratrade
Copy link
Member Author

I removed commit 2b52e77 for issue #2986 that removed the show method and show in routes.rb when not used. I will re-commit this at a later stage after we don't need the deprecation message any more on UI controllers.
Also, the 406 error for hosts and some other controllers was because of NO format.json when there IS a respond_to block. If there is NO respond_to block, then it's OK. So, I added format.json where necessary only for the purposes to avoid 406 error and get the deprecation error json response.

@domcleal
Copy link
Contributor

Good find, it worked properly in my test.

Thanks for the patches @isratrade, merged in as 9dc1001..bc89eb3 for Foreman 1.3.

@domcleal domcleal closed this Sep 10, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants