[Archivesspace_Users_Group] Creating settings for a plugin

Carlos Lemus carlos.lemus at unlv.edu
Mon Nov 2 16:51:23 EST 2015


Hello,

I just wanted to report on this for the record. I fixed it by renaming the
check_permissions function in my controller, apparently it was overriding
that of the preference controller and therefore it was trying to find the
marc_export_user_id in it's own schema.

Thank you,
Carlos Lemus

On Tue, Oct 27, 2015 at 3:07 PM, Carlos Lemus <carlos.lemus at unlv.edu> wrote:

> Hello Brian,
>
> your guidance has helped me set up the settings and they seem to be
> working now and uploaded to
> https://github.com/l3mus/ArchivesSpace-authority-project/tree/master/unlv_marc_exporter
> though I need to tweak a couple more things.
>
> I'm just having one trouble that the preferences are not saving now and
> it's,for some reason, trying to reference my settings schema and I end up
> getting the following below. I can't seem to figure out why it's
> referencing that marc_export_user_id when it's not part of the
> preferencecontroller. I even changed it to marc_export_user_id from user_id
> to try and avoid this problem.
> Do you have any ideas?
> Exception in PreferencesController#update
>
> Unknown response: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
> <html lang="en">
> <head>
>   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
>   <title>Internal Server Error at &#x2F;repositories&#x2F;2&#x2F;preferences&#x2F;4</title>
>   <meta name="robots" content="NONE,NOARCHIVE" />
>   <style type="text/css">
>     html * { padding:0; margin:0; }
>     body * { padding:10px 20px; }
>     body * * { padding:0; }
>     body { font:small sans-serif; background:#eee; }
>     body>div { border-bottom:1px solid #ddd; }
>     h1 { font-weight:normal; margin-bottom:.4em; }
>     h1 span { font-size:60%; color:#666; font-weight:normal; }
>     table { border:none; border-collapse: collapse; width:100%; }
>     td, th { vertical-align:top; padding:2px 3px; }
>     th { width:12em; text-align:right; color:#666; padding-right:.5em; }
>     #info { background:#f6f6f6; }
>     #info ol { margin: 0.5em 4em; }
>     #info ol li { font-family: monospace; }
>     #summary { background: #ffc; }
>     #explanation { background:#eee; border-bottom: 0px none; }
>   </style>
> </head>
> <body>
>   <div id="summary">
>     <h1>Internal Server Error <span>(500)</span></h1>
>     <table class="meta">
>       <tr>
>         <th>Request Method:</th>
>         <td>POST</td>
>       </tr>
>       <tr>
>         <th>Request URL:</th>
>       <td>http:&#x2F;&#x2F;localhost:8089&#x2F;repositories&#x2F;2&#x2F;preferences&#x2F;4</td>
>       </tr>
>     </table>
>   </div>
>   <div id="info">    <p>(NoMethodError) undefined method `marc_export_user_id&#x27; for nil:NilClass</p>
>   </div>
>
>   <div id="explanation">
>     <p>
>     You're seeing this error because you use <code>JRuby::Rack::ErrorApp::ShowStatus</code>.
>     </p>
>   </div>
> </body>
> </html>
>  (code: 500)
>
> Thank you,
>
> Carlos Lemus
>
>
> On Mon, Oct 19, 2015 at 6:52 AM, Brian Hoffman <brianjhoffman at gmail.com>
> wrote:
>
>> Hi Carlos,
>>
>> I think I see the problem - you’re copying from one of the more
>> idiosyncratic parts of the API, so it’s a bit hard to see what’s going on.
>> The preferences model in the backend builds a composite preferences object
>> by fetching all applicable rows from the table based on four contexts:
>>  global, repo, user_global, user_repo. These basically scope the data:
>> preferences for any user using any repo, any user using a particular repo,
>> a particular user using any repo, and a particular user using a particular
>> repo. The context of the request determines which contexts get loaded and
>> what kind of composite object gets assembled. But there is always at least
>> a ‘global’ preference representing the abstract ‘global’ repository. In the
>> preferences model, there’s an `init` method that takes care of creating
>> that record at startup:
>>
>>
>> https://github.com/archivesspace/archivesspace/blob/05f01f83414c6daa259e72abcc38b50d9450e769/backend/app/model/preference.rb#L7-L34
>>
>> So the frontend controller safely  assumes that there is always one
>> context preference for `global` and expects it to be on the json payload.
>> In your plugin, you don’t have the `init` logic so that’s not a safe
>> assumption. You could either add something similar, or just tweak the
>> frontend controller if the concept of ‘global’ plugin_settings doesn’t make
>> sense in your case.
>>
>> Brian
>>
>>
>>
>>
>> On Oct 15, 2015, at 5:49 PM, Carlos Lemus <carlos.lemus at unlv.edu> wrote:
>>
>> Hello Brian,
>>
>> Thank you for your recommendations, they've helped out a lot. I believe I
>> am very close to what I want to do and  what I want to achieve, but I've
>> reached a little snag and I can't find the problem.
>>
>> I took a little different path that I thought matched a bit closer to
>> what I wanted to accomplish through your suggestions and tried to mimic the
>> preferences/defaults. (a new version of my code at
>> https://github.com/l3mus/ArchivesSpace-authority-project/tree/master/plugin_settings
>> )
>>
>> At
>> https://github.com/l3mus/ArchivesSpace-authority-project/blob/master/plugin_settings/frontend/controllers/plugin_settings_controller.rb#L82
>>  I am getting a nil class error because it's not in the json and I can't
>> find the area where it gets added or if there is a step that I'm missing
>> for it to add that setting. I think it would be beneficial if the settings
>> could be edited in a per repository/per user basis like the preferences
>> seem to work.
>>
>> {"settings"=>{"ead_loc_text"=>"Findind Aid Location: "},
>> "global"=>#<JSONModel(:plugin_settings) {"id"=>1, "lock_version"=>22,
>> "json_schema_version"=>1, "repo_id"=>1, "user_uniq"=>"GLOBAL_USER",
>> "settings"=>#<JSONModel(:settings) {"ead_loc_text"=>"Findind Aid Location:
>> ", "jsonmodel_type"=>"settings"}>, "create_time"=>"2015-10-14T21:45:28Z",
>> "system_mtime"=>"2015-10-15T20:13:34Z",
>> "user_mtime"=>"2015-10-15T20:13:34Z", "jsonmodel_type"=>"plugin_settings",
>> "uri"=>"/repositories/1/plugin_settings/1"}>,
>> "settings_global"=>{"ead_loc_text"=>"Findind Aid Location: "}}
>>
>> it's missing that ['global']['repository']['ref'] value, I'm not sure
>> where it's coming from.
>>
>> The json above is coming from the following. It's either in here or
>> somewhere before that that global setting is set.
>>
>> https://github.com/l3mus/ArchivesSpace-authority-project/blob/master/plugin_settings/backend/model/plugin_settings.rb#L95
>>
>> I appreciate the help,
>>
>> Thank you,
>> Carlos Lemus
>>
>> On Tue, Oct 13, 2015 at 7:11 AM, Carlos Lemus <carlos.lemus at unlv.edu>
>> wrote:
>>
>>> Hello Brian,
>>>
>>> Thank you for the response.  I will definitely need more values so I'll
>>> try taking a look at the defaults controller.
>>> I'll let you know if I get something working.
>>>
>>> Thank you,
>>> Carlos Lemus
>>> On Oct 13, 2015 6:31 AM, "Brian Hoffman" <brianjhoffman at gmail.com>
>>> wrote:
>>>
>>>> Hi Carlos,
>>>>
>>>> I think you might want to look at the defaults controller and model, as
>>>> well as the sequence controller and model. If you really just need a single
>>>> string value, you may want to dispense with the JSONModel stuff completely
>>>> and just have your backend endpoint take a single parameter and update the
>>>> model.
>>>>
>>>> You can look at the DefaultValues model for an example of how to just
>>>> have 1 row in the table.
>>>>
>>>> For the frontend, you’re probably better off not using the handle_crud
>>>> helper if you don’t use JSONModel, and just have the controller prepare and
>>>> send an update request to the backend. The default_values example might
>>>> help here too:
>>>>
>>>> https://github.com/archivesspace/archivesspace/blob/master/frontend/app/models/default_values.rb
>>>>
>>>> Brian
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Oct 12, 2015, at 5:54 PM, Carlos Lemus <carlos.lemus at unlv.edu>
>>>> wrote:
>>>>
>>>> Hello,
>>>>
>>>> What I want to accomplish is to create a form, possibly in the
>>>> system_menu_controller, that will allow me to create certain
>>>> fields/settings with user-input values, save those values, and then let me
>>>> access them at different points in my plugin.
>>>>
>>>> What I've tried so far:
>>>>
>>>> I've tried to mimic a bit of the accessions_summary_reports and the
>>>> hello_world plugin. However, these seem both to be able to continuously
>>>> create new objects in the schema database pertaining to it, but I just want
>>>> to have one empty field for the settings that can just be updated instead
>>>> of having to create multiple settings. I have tried something similar with
>>>> the defaults, but I don't think I implemented them correctly.
>>>>
>>>> Here is a github link to my trial
>>>>
>>>> https://github.com/l3mus/ArchivesSpace-authority-project/tree/master/plugin_settings
>>>>
>>>> I hope that was clear enough, please let me know if I need to clarify
>>>> more.
>>>> I'm just looking for some direction on what I could be doing. How could
>>>> I approach doing this? I'm I looking in the right direction? Or is there a
>>>> better example that can help me form this?
>>>>
>>>> Thank you,
>>>>
>>>> Carlos Lemus
>>>> _______________________________________________
>>>> Archivesspace_Users_Group mailing list
>>>> Archivesspace_Users_Group at lyralists.lyrasis.org
>>>> http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group
>>>>
>>>>
>>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lyralists.lyrasis.org/pipermail/archivesspace_users_group/attachments/20151102/f28c0016/attachment.html>


More information about the Archivesspace_Users_Group mailing list