summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauri Ojansivu <x@xet7.org>2020-02-22 02:49:14 +0200
committerLauri Ojansivu <x@xet7.org>2020-02-22 02:49:14 +0200
commite0ca960a35cf006880019ba28fc82aa30f289a71 (patch)
treeb52103fa0a19ca0b066ddb5bea3b6ed78e569046
parent0e755e021b34de90617fa62eceb949ba5e19d39a (diff)
downloadwekan-e0ca960a35cf006880019ba28fc82aa30f289a71.tar.gz
wekan-e0ca960a35cf006880019ba28fc82aa30f289a71.tar.bz2
wekan-e0ca960a35cf006880019ba28fc82aa30f289a71.zip
Create New User in Admin Panel. Works, but does not save fullname yet,
so currently it's needed to edit add fullname later. Thanks to xet7 ! Related #802
-rw-r--r--client/components/settings/peopleBody.jade52
-rw-r--r--client/components/settings/peopleBody.js95
-rw-r--r--i18n/en.i18n.json5
-rw-r--r--models/users.js28
4 files changed, 179 insertions, 1 deletions
diff --git a/client/components/settings/peopleBody.jade b/client/components/settings/peopleBody.jade
index b8a94337..ca4bc382 100644
--- a/client/components/settings/peopleBody.jade
+++ b/client/components/settings/peopleBody.jade
@@ -40,9 +40,15 @@ template(name="peopleGeneral")
th {{_ 'active'}}
th {{_ 'authentication-method'}}
th
+ +newUserRow
each user in peopleList
+peopleRow(userId=user._id)
+template(name="newUserRow")
+ a.new-user
+ i.fa.fa-edit
+ | {{_ 'new'}}
+
template(name="peopleRow")
tr
if userData.loginDisabled
@@ -148,3 +154,49 @@ template(name="editUserPopup")
// div
// input#deleteButton.primary.wide(type="button" value="{{_ 'delete'}}")
+template(name="newUserPopup")
+ form
+ //label.hide.userId(type="text" value=user._id)
+ label
+ | {{_ 'fullname'}}
+ input.js-profile-fullname(type="text" value="" autofocus)
+ label
+ | {{_ 'username'}}
+ span.error.hide.username-taken
+ | {{_ 'error-username-taken'}}
+ //if isLdap
+ // input.js-profile-username(type="text" value=user.username readonly)
+ //else
+ input.js-profile-username(type="text" value="")
+ label
+ | {{_ 'email'}}
+ span.error.hide.email-taken
+ | {{_ 'error-email-taken'}}
+ //if isLdap
+ // input.js-profile-email(type="email" value="{{user.emails.[0].address}}" readonly)
+ //else
+ input.js-profile-email(type="email" value="")
+ label
+ | {{_ 'admin'}}
+ select.select-role.js-profile-isadmin
+ option(value="false" selected="selected") {{_ 'no'}}
+ option(value="true") {{_ 'yes'}}
+ label
+ | {{_ 'active'}}
+ select.select-active.js-profile-isactive
+ option(value="false" selected="selected") {{_ 'yes'}}
+ option(value="true") {{_ 'no'}}
+ label
+ | {{_ 'authentication-type'}}
+ select.select-authenticationMethod.js-authenticationMethod
+ each authentications
+ if isSelected value
+ option(value="{{value}}" selected) {{_ value}}
+ else
+ option(value="{{value}}") {{_ value}}
+ hr
+ label
+ | {{_ 'password'}}
+ input.js-profile-password(type="password")
+ div.buttonsContainer
+ input.primary.wide(type="submit" value="{{_ 'save'}}")
diff --git a/client/components/settings/peopleBody.js b/client/components/settings/peopleBody.js
index 8610034e..186afd58 100644
--- a/client/components/settings/peopleBody.js
+++ b/client/components/settings/peopleBody.js
@@ -39,6 +39,9 @@ BlazeComponent.extendComponent({
this.filterPeople();
}
},
+ 'click #newUserButton'() {
+ Popup.open('newUser');
+ },
},
];
},
@@ -141,6 +144,47 @@ Template.editUserPopup.helpers({
},
});
+Template.newUserPopup.onCreated(function() {
+ this.authenticationMethods = new ReactiveVar([]);
+ this.errorMessage = new ReactiveVar('');
+
+ Meteor.call('getAuthenticationsEnabled', (_, result) => {
+ if (result) {
+ // TODO : add a management of different languages
+ // (ex {value: ldap, text: TAPi18n.__('ldap', {}, T9n.getLanguage() || 'en')})
+ this.authenticationMethods.set([
+ { value: 'password' },
+ // Gets only the authentication methods availables
+ ...Object.entries(result)
+ .filter(e => e[1])
+ .map(e => ({ value: e[0] })),
+ ]);
+ }
+ });
+});
+
+Template.newUserPopup.helpers({
+ //user() {
+ // return Users.findOne(this.userId);
+ //},
+ authentications() {
+ return Template.instance().authenticationMethods.get();
+ },
+ //isSelected(match) {
+ // const userId = Template.instance().data.userId;
+ // const selected = Users.findOne(userId).authenticationMethod;
+ // return selected === match;
+ //},
+ //isLdap() {
+ // const userId = Template.instance().data.userId;
+ // const selected = Users.findOne(userId).authenticationMethod;
+ // return selected === 'ldap';
+ //},
+ errorMessage() {
+ return Template.instance().errorMessage.get();
+ },
+});
+
BlazeComponent.extendComponent({
onCreated() {},
user() {
@@ -155,6 +199,16 @@ BlazeComponent.extendComponent({
},
}).register('peopleRow');
+BlazeComponent.extendComponent({
+ events() {
+ return [
+ {
+ 'click a.new-user': Popup.open('newUser'),
+ },
+ ];
+ },
+}).register('newUserRow');
+
Template.editUserPopup.events({
submit(event, templateInstance) {
event.preventDefault();
@@ -248,3 +302,44 @@ Template.editUserPopup.events({
Popup.close();
}),
});
+
+Template.newUserPopup.events({
+ submit(event, templateInstance) {
+ event.preventDefault();
+ const fullname = templateInstance.find('.js-profile-fullname').value.trim();
+ const username = templateInstance.find('.js-profile-username').value.trim();
+ const password = templateInstance.find('.js-profile-password').value;
+ const isAdmin = templateInstance.find('.js-profile-isadmin').value.trim();
+ const isActive = templateInstance.find('.js-profile-isactive').value.trim();
+ const email = templateInstance.find('.js-profile-email').value.trim();
+
+ Meteor.call(
+ 'setCreateUser',
+ fullname,
+ username,
+ password,
+ isAdmin,
+ isActive,
+ email.toLowerCase(),
+ function(error) {
+ const usernameMessageElement = templateInstance.$('.username-taken');
+ const emailMessageElement = templateInstance.$('.email-taken');
+ if (error) {
+ const errorElement = error.error;
+ if (errorElement === 'username-already-taken') {
+ usernameMessageElement.show();
+ emailMessageElement.hide();
+ } else if (errorElement === 'email-already-taken') {
+ usernameMessageElement.hide();
+ emailMessageElement.show();
+ }
+ } else {
+ usernameMessageElement.hide();
+ emailMessageElement.hide();
+ Popup.close();
+ }
+ },
+ );
+ Popup.close();
+ },
+});
diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json
index da3d875a..bce99384 100644
--- a/i18n/en.i18n.json
+++ b/i18n/en.i18n.json
@@ -759,5 +759,8 @@
"assignee": "Assignee",
"cardAssigneesPopup-title": "Assignee",
"addmore-detail": "Add a more detailed description",
- "show-on-card": "Show on Card"
+ "show-on-card": "Show on Card",
+ "new": "New",
+ "editUserPopup-title": "Edit User",
+ "newUserPopup-title": "New User"
}
diff --git a/models/users.js b/models/users.js
index 7e23835c..00076253 100644
--- a/models/users.js
+++ b/models/users.js
@@ -620,6 +620,34 @@ Users.mutations({
});
Meteor.methods({
+ setCreateUser(fullname, username, password, isAdmin, isActive, email) {
+ if (Meteor.user().isAdmin) {
+ check(fullname, String);
+ check(username, String);
+ check(password, String);
+ check(isAdmin, String);
+ check(isActive, String);
+ check(email, String);
+
+ const nUsersWithUsername = Users.find({ username }).count();
+ const nUsersWithEmail = Users.find({ email }).count();
+ if (nUsersWithUsername > 0) {
+ throw new Meteor.Error('username-already-taken');
+ } else if (nUsersWithEmail > 0) {
+ throw new Meteor.Error('email-already-taken');
+ } else {
+ Accounts.createUser({
+ fullname,
+ username,
+ password,
+ isAdmin,
+ isActive,
+ email: email.toLowerCase(),
+ from: 'admin',
+ });
+ }
+ }
+ },
setUsername(username, userId) {
check(username, String);
check(userId, String);