[Freeipa-users] How to add multivalued attribute to UI

John Duino jduino at oblong.com
Wed Sep 16 22:21:47 UTC 2015


I found my mistake (I'd call it a typo but that would assume I knew what I was doing in the first place!)
In altemail.js, when defining the fields to be pushed, I used "type:" instead of "$type:". Once I fixed that (and restarted IPA, and cleared browser cache), it works as expected. For completeness, here is the full working plugin:

define([
        'freeipa/phases',
        'freeipa/user'],
        function(phases, user_mod) {

//helper function
function get_item(array, attr, value) {

        for (var i=0,l=array.length; i<l; i++) {
                if (array[i][attr] === value) return array[i];
        }
        return null;
}

var altemail_plugin = {};

// adds 'mailalternateaddress' field into user details facet
altemail_plugin.add_altemail_pre_op = function() {

        var facet = get_item(user_mod.entity_spec.facets, '$type', 'details');
        var section = get_item(facet.sections, 'name', 'contact');
        section.fields.push({
                $type: 'multivalued',
                name: 'mailalternateaddress',
                label: 'E-mail Alias'
        });
        return true;
};

phases.on('customization', altemail_plugin.add_altemail_pre_op);

return altemail_plugin;
});

----- Original Message -----
From: "John Duino" <jduino at oblong.com>
To: "freeipa-users" <freeipa-users at redhat.com>
Sent: Wednesday, September 16, 2015 1:16:13 PM
Subject: Re: [Freeipa-users] How to add multivalued attribute to UI

Oh, okay. I didn't realize the ipalib plugin affected the UI. Sure, I can share it. So in /usr/lib/python2.7/site-packages/ipalib/plugins/altemail.py is the following. I have also (at one point) had a validation function and a precallback (both currently not used when trying to simplify/test). Validation just checked for a validly formatted email address (I left the 'from' statement below which imports that library). The precallback was to ensure that the objectClass 'mailrecipient' was added to the user before trying to add the mailAlternateAddress attribute (It was causing some other error when it was already there..need to sort that out later, as well). Anyway, the ipalib plugin:

from ipalib.plugins import user
from ipalib.parameters import Str
from ipalib import _
from validate_email_address import validate_email

user.user.takes_params = user.user.takes_params + (
   Str('mailalternateaddress*',
       cli_name='altemail',
       label=_('E-mail Alias'),
       doc=_('E-Mail Alias'),
       minlength=7,
       multivalue=True,
   ),
)


----- Original Message -----
From: "Rob Crittenden" <rcritten at redhat.com>

I don't know a lot about the UI javascript but there are two pieces to
code: the plugin to define the attribute and the UI to consume it.

It sounds like you've done both. What I'm interested in is how you
configured the plugin. Can you share the code?

The UI downloads all the available commands and options as metadata and
uses that to help drive some of the interactions.

rob

> 
> Thanks!
> ----- Original Message -----
> From: "Rob Crittenden" <rcritten at redhat.com>
> 
> Do you have this configured in the user plugin? Perhaps some other piece
> of the UI is confused because of either a missing or misconfigured value
> for the attribute in the metadata.
> 
> If you do, how is the param configured?
> 
> rob
>




More information about the Freeipa-users mailing list