| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118 |
1
1
1
1
1
5
5
5
5
5
4
5
4
4
4
4
1
1
4
3
3
3
3
3
1
1
3
1
| 'use strict';
;require.register("models/user", function (exports, require, module) {
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var App = require('app');
var validator = require('utils/validator');
App.User = DS.Model.extend({
userName: DS.attr('string'),
id: Em.computed.alias('userName'),
userType: DS.attr('string'),
auditItems: DS.hasMany('App.ServiceAudit'),
admin: DS.attr('boolean'),
operator: DS.attr('boolean'),
clusterUser: DS.attr('boolean'),
/**
* List of permissions assigned to user
* Available permissions:
* AMBARI.ADMINISTRATOR
* CLUSTER.USER
* CLUSTER.ADMINISTRATOR
* VIEW.USER
* @property {Array} permissions
**/
permissions: DS.attr('array'),
/**
* @type {Boolean}
*/
isLdap: Em.computed.equal('userType', 'LDAP')
});
App.CreateUserForm = App.Form.extend({
className: App.User,
object: Em.computed.alias('App.router.mainAdminUserCreateController.content'),
fieldsOptions: [{ name: "userName", displayName: "Username", toLowerCase: function () {
var v = this.get('value');this.set('value', v.toLowerCase());
}.observes('value') }, { name: "password", displayName: "Password", displayType: "password", isRequired: true }, { name: "passwordRetype", displayName: "Retype Password", displayType: "password", validator: "passwordRetype", isRequired: true }, { name: "admin", displayName: "Admin", displayType: "checkbox", isRequired: false, defaultValue: true }],
fields: [],
isValid: function isValid() {
var isValid = this._super();
var passField = this.get('field.password');
var passRetype = this.get('field.passwordRetype');
if (!validator.empty(passField.get('value'))) {
Iif (passField.get('value') != passRetype.get('value')) {
passRetype.set('errorMessage', this.t('admin.users.createError.passwordValidation'));
isValid = false;
}
}
if (isValid) {
var users = App.User.find();
var userNameField = this.getField('userName');
var userName = userNameField.get('value');
if (users.mapProperty('userName').contains(userName)) {
userNameField.set('errorMessage', this.t('admin.users.createError.userNameExists'));
return isValid = false;
}
}
return isValid;
},
isWarn: function isWarn() {
var isWarn = false;
var userNameField = this.getField('userName');
userNameField.set('warnMessage', '');
var userName = userNameField.get('value');
if (this.isValid() && !validator.isValidUserName(userName)) {
userNameField.set('warnMessage', this.t('users.userName.validationFail'));
isWarn = true;
}
return isWarn;
},
save: function save() {
var object = this.get('object');
var formValues = {};
$.each(this.get('fields'), function () {
formValues[Ember.String.decamelize(this.get('name'))] = this.get('value');
});
if (this.get('className')) {
App.store.safeLoad(this.get('className'), App.dateTime(), formValues);
}
this.set('result', 1);
return true;
}
});
App.User.FIXTURES = [];
}); |