Rocket.chat: How to add fields to the users?

Created on 22 Feb 2016  路  32Comments  路  Source: RocketChat/Rocket.Chat

I would like to add fields to the user registration!

The registration only ask for and user name & email.

I try but I can't do it :S

[UPDATE]

What i try is adding fields in the registerUser.coffe :

userData =
email: formData.email
password: formData.pass
lastname: 'lastName'

But it does not work :S, I get an error on meteor terminal:

Error: A method named 'registerUser' is already defined
at livedata_server.js:1542:15
at Function._.each._.forEach (packages/underscore/underscore.js:113:1)
at [object Object]._.extend.methods (livedata_server.js:1538:7)
at Object.Meteor.methods (server/lib/debug.js:33:2)
at server/methods/registerUser.js:2:1
at server/methods/registerUser.js:22:1

Request discussion

Most helpful comment

@vfxpandit I've added custom fields and there is no fields visible in user profile (user can't set field).

All 32 comments

@RocketChat/core what do you think about this issue?

@elgriego,

Actually, userData (where you're trying to add the lastname) is passed to Accounts.createUser which is a meteor function and which won't save extra data.
Just have a look a bit below, I think you can do something like: RocketChat.models.Users.setName userId, formData.name

We should have a way to define extra fields for the registration form (similar to the settings?), but I can imagined it getting much more complex very soon, as admin will want to configure validations, etc.

But I agree, we should have some easy way to add more fields.

Related: #2046

related #2048

@RocketChat/core I'm working on this issue with @nazclarion. We're wondering where in mongo is the best place for user field extensions - A) in the user document, B) nested in a property of user (like custom-fields), C) in a seperate collection?

I鈥檓 not sure what that means for migrations with different versions / branches. If we populate custom fields then build a version that doesn鈥檛 have this package, are there DB migrations that would remove the changes?

Speaking of validations etc, I'd like to work towards a more unified approach to encourage consistency with admin controls and settings pages, which is kinda lacking at present.
I've looked into how other Meteor projects do that and found a possible approach, using a few packages together to provide schemas for auto-building forms. Maybe there's some packages already doing this? e.g.

aldeed:simple-schema combined with aldeed:collection2. Then possible to also use aldeed:autoform to generate form UI straight from the collection schema, no template markup required.

OR

More manual, less prescriptive approach could just be providing a front end validator to all packages, something like Parsley.js.

Thoughts?

It would also be useful to have these "About me"/"Role" fields be searchable from a system-wide search feature that searches among all chats and user profiles, so that I could search for expertise within my organization using the search feature.

I would also like this feature, synced from ldap. Essentially, the additional fields could be added to 'User Data Field Map' under Admin -> LDAP. Any hints on where to start?

@cbrummitt, @VirtuaCreative, @estadtherr, @meilinger, @joetm, @Schoaf, @svenschumacher, @gongled, @jcardila @acaronmd lets use this issue to track your request from https://github.com/RocketChat/Rocket.Chat/issues/2046

@timkinnane and @rodrigok can we have a chat about this on our demo server?

I agree it is needed, together with #2135 :)

Add fields in registration process was done here https://github.com/RocketChat/Rocket.Chat/pull/4073

+1

@RocketChat/core is there anything needed done on this? From what I can tell #4073 should have resolved this.

@geekgonecrazy Documentation on how it works and how to use it.

Hey, i'm trying to add some customFields using the api/v1/users.update method.

It seems that my HTTP calls are successful (e.g. i'm managing to update the "name" field; or add complete new users). nonetheless, it seems that i can't update (or add) customField - as it doesn't appear in the user data on mongoDB.

 var options = {
        url: url +"/api/v1/users.update",
        method: 'POST',
        headers: {
            "X-Auth-Token": credentials.authToken,
            "X-User-Id": credentials.userId,
            "Content-type": "application/json"
        },
        form: {userId: userId, data: {customFields: {twitter:"something"}, name: "ido try"}}
    }
request(options, function(err, res, body) {
        var bodyParse= JSON.parse(body)
        console.log(bodyParse)
    })

@shaharido1 I'm having the same problem. Were you able to resolve this?

have you guys correctly configured the Custom Fields under Administration > Accounts > Registration?

@sampaiodiego I have not. I just added the fields manual to my document i.e.

"_id" : "Giek2324dsd",
"customFields" : {
"situation" : "I was hurt by a person.",
"amount" : "50",
"isShowing" : false
}

So I have to add the custom fields in the admin section and then the API (users.update) will work?

Syirrus

So I have to add the custom fields in the admin section and then the API (users.update) will work?

Yes, exactly

@sampaiodiego I added the custom fields as such to the Admin section:

{
"bounty" : {
"situation": "text",
"willPay": "text",
"isShowing": false
}
}

I'm POSTing to my url and get the following return:

[all of my JSON data for "_id"]
"success": true

But, when I look at my "bounty" key it's exactly the same
I've checked my variable types and all is consistent with what I added in the Custom Section.

Any ideas?

@sampaiodiego nevermind I took a break and looked at what I was doing and figured it out. Sorry for bothering you and thank you for your response earlier!

Hey @Syirrus I also missed the part of adding the fields to the registration tab. Maybe it's worth to add it to the docs, as it's not very intuitive..

How can i add the field i created to my info sidebar?

Is it possible to make this deleteable or changeable by the administrator?
Like I can change a users name and password and but not the custom fields.

I don't think that you can change it from the GUI (only through the rest API).

I had a look into the pull request and figured out, that you should see the fields if you have view-full-other-user-info, which seems not to work with my server right now.
I can change the custom field i created but it's not possible for me to have insight in them.
Maybe @sampaiodiego could have a look at this issue?

Also: is it possible to declare single fields as public, so that you can choose if fields should be visible for everyone, not just for administrators?

Same problem here. Add custom fields to Accounts/Custom Fields, but don't see them in user's profile. view-full-other-user-info is enabled for admin and users.

Same problem with RocketChat 0.56.0. Users can see/update custom fields in their own profile but it's not displayed for others even with view-full-other-user-info enabled.

Any leads ?

I have a scenario in my case where I need to have a custom field as a list in which I could insert as well as delete elements . Which type of custom field I should create ?

Use this syntax to display custom fields in profile
http://rocketchat/admin/Accounts

Custom Fields to Show in User Info >>
[{"Designation": "designation"}, {"Department": "department"}]

Registration >> Custom Fields
sample json format for add custom fields

{
   "designation": {"type": "text",
       "required": false,
       "minLength": 2,
       "maxLength": 100}, 
   "department": {"type": "text",
       "required": false,
       "minLength": 2,
       "maxLength": 100}
}

To update custom fields though Rest API
"data": {"name": name, "email": email, "customFields": {"designation": 'Artist', 'department': 'Modeling'}}}

@vfxpandit I've added custom fields and there is no fields visible in user profile (user can't set field).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chrisvella picture chrisvella  路  96Comments

engelgabriel picture engelgabriel  路  158Comments

johnyb0y picture johnyb0y  路  53Comments

mitar picture mitar  路  68Comments

bazarnew picture bazarnew  路  87Comments