[PATCH/foreman 1/1] Fixes #1123 - api for config_templates returns too much data

Signed-off-by: Corey Osman <corey@logicminds.biz>

··· --- app/models/config_template.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/app/models/config_template.rb b/app/models/config_template.rb
index ab1e6fd…66f0839 100644
— a/app/models/config_template.rb
+++ b/app/models/config_template.rb
@@ -87,7 +87,7 @@ class ConfigTemplate < ActiveRecord::Base
end

def as_json(options={})

  • super({:only => [:name, :template, :snippet]}.merge(options))
  • super({:only => [:name, :id, :snippet],:include => [:template_kind]}.merge(options))
    end

end

1.7.4.1

>
> Signed-off-by: Corey Osman <corey@logicminds.biz>
> —
> app/models/config_template.rb | 2 ±
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/app/models/config_template.rb b/app/models/config_template.rb
> index ab1e6fd…66f0839 100644
> — a/app/models/config_template.rb
> +++ b/app/models/config_template.rb
> @@ -87,7 +87,7 @@ class ConfigTemplate < ActiveRecord::Base
> end
>
> def as_json(options={})
> - super({:only => [:name, :template, :snippet]}.merge(options))
> + super({:only => [:name, :id, :snippet],:include => [:template_kind]}.merge(options))

hmm… How would you get the actual template then?

e.g. one of the usage case is to store the templates in git, or edit
them in your favorite editor, i think it should be possible to extract
that bit.

maybe you want to exclude the template for the index action?

Thanks,
Ohad

··· On Sun, Aug 28, 2011 at 8:25 PM, Corey Osman wrote: > end > > end > -- > 1.7.4.1 > >

>>
>> Signed-off-by: Corey Osman <corey@logicminds.biz>
>> —
>> app/models/config_template.rb | 2 ±
>> 1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/app/models/config_template.rb b/app/models/config_template.rb
>> index ab1e6fd…66f0839 100644
>> — a/app/models/config_template.rb
>> +++ b/app/models/config_template.rb
>> @@ -87,7 +87,7 @@ class ConfigTemplate < ActiveRecord::Base
>> end
>>
>> def as_json(options={})
>> - super({:only => [:name, :template, :snippet]}.merge(options))
>> + super({:only => [:name, :id, :snippet],:include => [:template_kind]}.merge(options))
>
> hmm… How would you get the actual template then?

I don't need the template just the name, id, and kind.

>
> e.g. one of the usage case is to store the templates in git, or edit
> them in your favorite editor, i think it should be possible to extract
> that bit.
are you suggestion that foreman maintain its own git repo for templates? That would be cool.

>
> maybe you want to exclude the template for the index action?

I don't need to see the template. I think if one wanted to get the template itself it should be in a show action but it looks like the edit action sort of does something similar so I wasn't sure.

··· On Sep 7, 2011, at 11:19 PM, Ohad Levy wrote: > On Sun, Aug 28, 2011 at 8:25 PM, Corey Osman wrote:

Thanks,
Ohad

end

end

1.7.4.1

>
>
>>>
>>> Signed-off-by: Corey Osman <corey@logicminds.biz>
>>> —
>>> app/models/config_template.rb | 2 ±
>>> 1 files changed, 1 insertions(+), 1 deletions(-)
>>>
>>> diff --git a/app/models/config_template.rb b/app/models/config_template.rb
>>> index ab1e6fd…66f0839 100644
>>> — a/app/models/config_template.rb
>>> +++ b/app/models/config_template.rb
>>> @@ -87,7 +87,7 @@ class ConfigTemplate < ActiveRecord::Base
>>> end
>>>
>>> def as_json(options={})
>>> - super({:only => [:name, :template, :snippet]}.merge(options))
>>> + super({:only => [:name, :id, :snippet],:include => [:template_kind]}.merge(options))
>>
>> hmm… How would you get the actual template then?
>
> I don't need the template just the name, id, and kind.
yeah, but imho the api should still expose it for what ever reason…
>
>>
>> e.g. one of the usage case is to store the templates in git, or edit
>> them in your favorite editor, i think it should be possible to extract
>> that bit.
> are you suggestion that foreman maintain its own git repo for templates? That would be cool.
>
I didnt exactly say that, I know that some people want to add git
backend to store the templates… and yes we need some sort of versions
for templates (there are a few rails plugin to store it in the db
similar to how wikis do it), but regardless, that was just one example
of how someone might use the api.

>>
>> maybe you want to exclude the template for the index action?
>
> I don't need to see the template. I think if one wanted to get the template itself it should be in a show action but it looks like the edit action sort of does something similar so I wasn't sure.
right, but the as_json you did, is effecting both… one of the reasons
you do a merge with options there, is that you could pass more options
such as exclude templates on index :wink:

Ohad

··· On Thu, Sep 8, 2011 at 7:44 PM, Corey Osman wrote: > On Sep 7, 2011, at 11:19 PM, Ohad Levy wrote: >> On Sun, Aug 28, 2011 at 8:25 PM, Corey Osman wrote: > >> >> Thanks, >> Ohad >>> end >>> >>> end >>> -- >>> 1.7.4.1 >>> >>> > >

>>
>>
>>>>
>>>> Signed-off-by: Corey Osman <corey@logicminds.biz>
>>>> —
>>>> app/models/config_template.rb | 2 ±
>>>> 1 files changed, 1 insertions(+), 1 deletions(-)
>>>>
>>>> diff --git a/app/models/config_template.rb b/app/models/config_template.rb
>>>> index ab1e6fd…66f0839 100644
>>>> — a/app/models/config_template.rb
>>>> +++ b/app/models/config_template.rb
>>>> @@ -87,7 +87,7 @@ class ConfigTemplate < ActiveRecord::Base
>>>> end
>>>>
>>>> def as_json(options={})
>>>> - super({:only => [:name, :template, :snippet]}.merge(options))
>>>> + super({:only => [:name, :id, :snippet],:include => [:template_kind]}.merge(options))
>>>
>>> hmm… How would you get the actual template then?
>>
>> I don't need the template just the name, id, and kind.
> yeah, but imho the api should still expose it for what ever reason…
>>
>>>
>>> e.g. one of the usage case is to store the templates in git, or edit
>>> them in your favorite editor, i think it should be possible to extract
>>> that bit.
>> are you suggestion that foreman maintain its own git repo for templates? That would be cool.
>>
> I didnt exactly say that, I know that some people want to add git
> backend to store the templates… and yes we need some sort of versions
> for templates (there are a few rails plugin to store it in the db
> similar to how wikis do it), but regardless, that was just one example
> of how someone might use the api.
>
>>>
>>> maybe you want to exclude the template for the index action?
>>
>> I don't need to see the template. I think if one wanted to get the template itself it should be in a show action but it looks like the edit action sort of does something similar so I wasn't sure.
> right, but the as_json you did, is effecting both… one of the reasons
> you do a merge with options there, is that you could pass more options
> such as exclude templates on index :wink:

so what if we did index with a showcode=true parameter?
How do I pass a parameter down to the model?

format.json { render :json => values}

Also, how does this parameter make its way into the as_json function so that I can add a condition to show the extra code or not.

def as_json(options={})
super({:only => [:name, :id, :snippet],:include => [:template_kind]}.merge(options))

··· On Sep 8, 2011, at 10:20 AM, Ohad Levy wrote: > On Thu, Sep 8, 2011 at 7:44 PM, Corey Osman wrote: >> On Sep 7, 2011, at 11:19 PM, Ohad Levy wrote: >>> On Sun, Aug 28, 2011 at 8:25 PM, Corey Osman wrote:

Ohad

Thanks,
Ohad

end

end

1.7.4.1