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 #9031 - Add routes to view template_combinations per hostgroup / env #2259

Closed
wants to merge 1 commit into from

Conversation

shlomizadok
Copy link
Member

Created under /api/v2/hostgroups/:id/template_combinations and /api/v2/environments/:id/template_combinations, as it seems more reasonable.

I have also added the option to update template combinations.

Environment.authorized(:view_templates).find(params[:environment_id]) rescue nil
end

def requested_resource
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to use the find_*_nested_object support in the API base controller here? It looks like you'd just specify allowed_nested_id and it could look up the base object.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -28,6 +41,16 @@ def create
def show
end

api :PUT, "/config_templates/:config_template_id/template_combinations/:id", N_("Update template combination")
api :PUT, "/hostgroups/:hostgroup_id/template_combinations/:id", N_("Update template combination")
api :PUT, "/environments/:environment_id/template_combinations/:id", N_("Update template combination")
Copy link
Contributor

Choose a reason for hiding this comment

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

you need to define :config_template_id/hostgroup_id etc. They're already on the actions above, so I'd suggest creating a param_group and using that on all three actions to avoid copy/pasting it a third time.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, though I really wanted to copy and paste three times

end

api :POST, "/config_templates/:config_template_id/template_combinations", N_("Add a template combination")
api :POST, "/hostgroups/:hostgroup_id/template_combinations", N_("Add a template combination")
api :POST, "/environments/:environment_id/template_combinations", N_("Add a template combination")
Copy link
Contributor

Choose a reason for hiding this comment

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

These routes don't seem to work, they're not listed in rake routes for me and I get: ActionController::RoutingError (No route matches [POST] "/api/v2/environments/production/template_combinations")

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems to work now.

@shlomizadok
Copy link
Member Author

Weird, my rake routes shows route to /api/v2/environments/production/template_combinations (http://fpaste.org/221463/31517887/ line 8), I am also able to post (yet getting double_render error.... [fixing])

@config_template = ConfigTemplate.authorized(:view_templates).find(params[:config_template_id]) rescue nil
end

def requested_resource
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary any more? It looks like find_parent_config_template is handled by the nested resource filter, and that the "return not_found" part could be handled by using find_required_nested_obj rather than optional. Or is there a subtle difference?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is necessary, the subtle difference is that we'd like to return one of config_template OR nested_obj as the resource for the template combination (tests fail w/o assigning this resource).

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I don't think I was clear by putting this comment on the wrong line. I meant to ask whether find_parent_config_template is required, because config_template_id is in the allowed_nested_id list. Then everything is handled via the nested object lookup in the base controller, and all we need nested_obj.

e.g. domcleal@a298ae5

Tests pass for me, but to be honest, they're not very thorough...

@@ -36,9 +62,13 @@ def destroy
end

def find_parent_config_template
Copy link
Contributor

Choose a reason for hiding this comment

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

also unused? I can't see any references to @config_template, I'm pretty sure it's all going through nested_obj now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually @config_template is used and is required by :index, :create (failing without it.)
I tried to removed it, as I thought it will be through nested_obj but those actions require it.

reference: https://github.com/shlomizadok/foreman/blob/fix_9031/app/controllers/api/v2/template_combinations_controller.rb#L6

Copy link
Contributor

Choose a reason for hiding this comment

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

I see in your link that this filter's called, but both methods called nested_obj. It seems to work here when I comment out the filter, what error do you see?

Copy link
Member Author

Choose a reason for hiding this comment

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

The error I see is me forgetting to remove the before_filter 😳

@domcleal
Copy link
Contributor

domcleal commented Jun 1, 2015

Merged as ee66b3a, thanks @shlomizadok.

@domcleal domcleal closed this Jun 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants