Изменена струкрута данных

1 parent 001a2435
...@@ -19,7 +19,8 @@ Ext.define('MyMA.controller.Transports', { ...@@ -19,7 +19,8 @@ Ext.define('MyMA.controller.Transports', {
click: this.onActionColumn click: this.onActionColumn
}, },
'transports > grid': { 'transports > grid': {
edit: this.onEditAction edit: this.onEditAction,
afterrender: this.onGridRender
} }
}); });
}, },
...@@ -77,7 +78,9 @@ Ext.define('MyMA.controller.Transports', { ...@@ -77,7 +78,9 @@ Ext.define('MyMA.controller.Transports', {
* Search action * Search action
*/ */
onSearch: function(Button) { onSearch: function(Button) {
this.getTransportsList().getStore().reload({ params: Button.up('toolbar').getValues() }); var store = this.getTransportsList().getStore();
store.getProxy().extraParams = Ext.apply({}, Button.up('toolbar').getValues());
store.reload();
}, },
...@@ -93,5 +96,13 @@ Ext.define('MyMA.controller.Transports', { ...@@ -93,5 +96,13 @@ Ext.define('MyMA.controller.Transports', {
this.store.reload(); this.store.reload();
} }
}); });
},
/**
* Fires when widget is shown
*/
onGridRender: function(grid) {
grid.getStore().reload();
} }
}); });
Ext.define('MyMA.controller.User', { Ext.define('MyMA.controller.User', {
extend: 'Ext.app.Controller', extend: 'Ext.app.Controller',
views: ['User'], views: ['User'],
stores: ['UserTransport'],
refs: [{ refs: [{
selector: 'user', selector: 'user',
ref: 'userWindow' ref: 'userWindow'
...@@ -26,9 +27,11 @@ Ext.define('MyMA.controller.User', { ...@@ -26,9 +27,11 @@ Ext.define('MyMA.controller.User', {
url: Ext.Ajax.getRestUrl('api','user', id), url: Ext.Ajax.getRestUrl('api','user', id),
clientValidation: true, clientValidation: true,
method: id > 0 ? 'PUT' : 'POST', method: id > 0 ? 'PUT' : 'POST',
params: Ext.applyIf(Ext.copyTo({}, form.getValues(), 'smtp,imap,manager'), { params: Ext.applyIf(Ext.copyTo({}, form.getValues(), 'smtp,imap,pop3,sieve,manager'), {
smtp: 0, smtp: 0,
imap: 0, imap: 0,
pop3: 0,
sieve: 0,
manager: 0 manager: 0
}), }),
scope: { scope: {
......
...@@ -20,6 +20,9 @@ Ext.define('MyMA.controller.Users', { ...@@ -20,6 +20,9 @@ Ext.define('MyMA.controller.Users', {
}, },
'users actioncolumn': { 'users actioncolumn': {
click: this.onActionColumn click: this.onActionColumn
},
'users > grid': {
afterrender: this.onGridRender
} }
}); });
}, },
...@@ -79,9 +82,19 @@ Ext.define('MyMA.controller.Users', { ...@@ -79,9 +82,19 @@ Ext.define('MyMA.controller.Users', {
/** /**
* Search action * Search action
*/ */
onSearch: function(Button) { onSearch: function(Button) {
this.getUsersList().getStore().reload({ params: Button.up('toolbar').getValues() }); var store = this.getUsersList().getStore();
} store.getProxy().extraParams = Ext.apply({}, Button.up('toolbar').getValues());
store.reload();
},
/**
* Fires when widget is shown
*/
onGridRender: function(grid) {
grid.getStore().reload();
}
}); });
...@@ -7,6 +7,9 @@ Ext.define('MyMA.model.Transports', { ...@@ -7,6 +7,9 @@ Ext.define('MyMA.model.Transports', {
name: 'domain', name: 'domain',
type: 'string' type: 'string'
}, { }, {
name: 'rootdir',
type: 'string'
}, {
name: 'transport', name: 'transport',
type: 'string' type: 'string'
}], }],
......
...@@ -3,33 +3,30 @@ Ext.define('MyMA.model.Users', { ...@@ -3,33 +3,30 @@ Ext.define('MyMA.model.Users', {
fields: [{ fields: [{
name: 'id', name: 'id',
type: 'int' type: 'int'
}, { }, 'name', 'login', 'passwd', {
name: 'name',
type: 'string'
}, {
name: 'login',
type: 'string'
}, {
name: 'passwd',
type: 'string'
}, {
name: 'uid', name: 'uid',
type: 'int', type: 'int',
defaultValue: 8 defaultValue: 8
}, { }, {
name: 'domid',
type: 'int'
}, {
name: 'gid', name: 'gid',
type: 'int', type: 'int',
defaultValue: 12 defaultValue: 12
}, { }, {
name: 'maildir',
type: 'string'
}, {
name: 'smtp', name: 'smtp',
type: 'int' type: 'int'
}, { }, {
name: 'imap', name: 'imap',
type: 'int' type: 'int'
}, { }, {
name: 'pop3',
type: 'int'
}, {
name: 'sieve',
type: 'int'
}, {
name: 'quota', name: 'quota',
type: 'int', type: 'int',
defaultValue: 10000000 defaultValue: 10000000
...@@ -42,12 +39,7 @@ Ext.define('MyMA.model.Users', { ...@@ -42,12 +39,7 @@ Ext.define('MyMA.model.Users', {
}, { }, {
name: 'backup_last', name: 'backup_last',
type: 'date' type: 'date'
}], }, 'domain' ],
validations: [{
type: 'format',
field: 'maildir',
matcher: /^\/[a-z]\.ru\/[a-z_0-9]\/Maildir\/$/
}],
proxy: { proxy: {
type: 'rest', type: 'rest',
url: Ext.Ajax.getRestUrl('api/user'), url: Ext.Ajax.getRestUrl('api/user'),
......
Ext.define('MyMA.store.UserTransport', {
extend: 'Ext.data.Store',
requires: 'MyMA.model.Transports',
model: 'MyMA.model.Transports',
autoLoad: true,
remoteSort: true,
pageSize: 100
});
...@@ -52,7 +52,15 @@ Ext.define('MyMA.view.Transports', { ...@@ -52,7 +52,15 @@ Ext.define('MyMA.view.Transports', {
xtype: 'textfield', xtype: 'textfield',
allowBlank: false allowBlank: false
}, },
flex: 1 flex: 2
}, {
header: 'Root direcotry for the users',
dataIndex: 'rootdir',
flex: 1,
editor: {
xtype: 'textfield',
allowBlank: false
}
}, { }, {
header: 'Transport', header: 'Transport',
dataIndex: 'transport' dataIndex: 'transport'
......
...@@ -40,12 +40,41 @@ Ext.define('MyMA.view.User', { ...@@ -40,12 +40,41 @@ Ext.define('MyMA.view.User', {
name: 'imap', name: 'imap',
inputValue: 1 inputValue: 1
}, { }, {
xtype: 'checkbox',
fieldLabel: 'POP3',
name: 'pop3',
inputValue: 1
}, {
xtype: 'checkbox',
fieldLabel: 'Sieve',
name: 'sieve',
inputValue: 1
}, {
fieldLabel: 'Name', fieldLabel: 'Name',
name: 'name' name: 'name'
}, { }, {
xtype: 'fieldcontainer',
layout: 'hbox',
fieldLabel: 'Login', fieldLabel: 'Login',
name: 'login', items: [{
vtype: 'email' xtype: 'textfield',
name: 'login',
width: 100,
allowBlank: false
}, {
xtype: 'tbspacer',
width: 5
}, {
xtype: 'combo',
name: 'domid',
allowBlank: false,
valueField: 'id',
displayField: 'domain',
store: 'UserTransport',
editable: false,
queryMode: 'local',
flex: 1
}]
}, { }, {
fieldLabel: 'Password', fieldLabel: 'Password',
name: 'passwd' name: 'passwd'
...@@ -64,9 +93,6 @@ Ext.define('MyMA.view.User', { ...@@ -64,9 +93,6 @@ Ext.define('MyMA.view.User', {
anchor: '50%', anchor: '50%',
value: 12 value: 12
}, { }, {
fieldLabel: 'Mail directory',
name: 'maildir'
}, {
xtype: 'numberfield', xtype: 'numberfield',
name: 'quota', name: 'quota',
allowDecimal: false, allowDecimal: false,
......
...@@ -104,7 +104,10 @@ Ext.define('MyMA.view.Users', { ...@@ -104,7 +104,10 @@ Ext.define('MyMA.view.Users', {
}, { }, {
header: 'Login', header: 'Login',
dataIndex: 'login', dataIndex: 'login',
width: 120 width: 120,
renderer: function(value, meta, record) {
return value + '@' + record.get('domain');
}
}, { }, {
header: 'Password', header: 'Password',
hidden: true, hidden: true,
...@@ -120,9 +123,6 @@ Ext.define('MyMA.view.Users', { ...@@ -120,9 +123,6 @@ Ext.define('MyMA.view.Users', {
hidden: true, hidden: true,
width: 40 width: 40
}, { }, {
header: 'Mail directory',
dataIndex: 'maildir'
}, {
header: 'SMTP', header: 'SMTP',
dataIndex: 'smtp', dataIndex: 'smtp',
width: 55, width: 55,
...@@ -159,6 +159,42 @@ Ext.define('MyMA.view.Users', { ...@@ -159,6 +159,42 @@ Ext.define('MyMA.view.Users', {
return 'No'; return 'No';
} }
}, { }, {
header: 'POP3',
dataIndex: 'pop3',
width: 55,
editor: {
xtype: 'combo',
valueField: 'id',
displayField: 'name',
triggerAction: 'all',
editable: false,
store: 'Choice'
},
renderer: function(value) {
if(value==1) {
return 'Yes';
}
return 'No';
}
}, {
header: 'Sieve',
dataIndex: 'sieve',
width: 55,
editor: {
xtype: 'combo',
valueField: 'id',
displayField: 'name',
triggerAction: 'all',
editable: false,
store: 'Choice'
},
renderer: function(value) {
if(value==1) {
return 'Yes';
}
return 'No';
}
}, {
header: 'Quota', header: 'Quota',
dataIndex: 'quota', dataIndex: 'quota',
editor: { editor: {
......
...@@ -309,10 +309,12 @@ Ext.define('MyMA.view.Users', { ...@@ -309,10 +309,12 @@ Ext.define('MyMA.view.Users', {
}, { }, {
header: 'uid', header: 'uid',
dataIndex: 'uid', dataIndex: 'uid',
hidden: true,
width: 40 width: 40
}, { }, {
header: 'gid', header: 'gid',
dataIndex: 'gid', dataIndex: 'gid',
hidden: true,
width: 40 width: 40
}, { }, {
header: 'Mail directory', header: 'Mail directory',
...@@ -320,6 +322,7 @@ Ext.define('MyMA.view.Users', { ...@@ -320,6 +322,7 @@ Ext.define('MyMA.view.Users', {
}, { }, {
header: 'SMTP', header: 'SMTP',
dataIndex: 'smtp', dataIndex: 'smtp',
width: 55,
editor: { editor: {
xtype: 'combo', xtype: 'combo',
valueField: 'id', valueField: 'id',
...@@ -337,6 +340,7 @@ Ext.define('MyMA.view.Users', { ...@@ -337,6 +340,7 @@ Ext.define('MyMA.view.Users', {
}, { }, {
header: 'IMAP', header: 'IMAP',
dataIndex: 'imap', dataIndex: 'imap',
width: 55,
editor: { editor: {
xtype: 'combo', xtype: 'combo',
valueField: 'id', valueField: 'id',
...@@ -359,6 +363,16 @@ Ext.define('MyMA.view.Users', { ...@@ -359,6 +363,16 @@ Ext.define('MyMA.view.Users', {
allowDecimal: false allowDecimal: false
} }
}, { }, {
header: 'Backup (days)',
dataIndex: 'backup',
renderer: function(value) {
return value == 0 ? 'Off' : value;
}
}, {
header: 'Last Backup',
dataIndex: 'backup_last',
renderer: Ext.util.Format.dateRenderer('d.m.Y H:i')
}, {
xtype: 'actioncolumn', xtype: 'actioncolumn',
width: 30, width: 30,
items: [{ items: [{
...@@ -445,6 +459,14 @@ Ext.define('MyMA.view.User', { ...@@ -445,6 +459,14 @@ Ext.define('MyMA.view.User', {
fieldLabel: 'Quota', fieldLabel: 'Quota',
anchor: '60%', anchor: '60%',
value: 100000000 value: 100000000
}, {
xtype: 'numberfield',
name: 'backup',
allowDecimal: false,
fieldLabel: 'Backup (day)',
anchor: '60%',
maxValue: 7,
minValue: 0
}] }]
}] }]
}); });
......
...@@ -29,20 +29,22 @@ class UserIdentity extends CUserIdentity ...@@ -29,20 +29,22 @@ class UserIdentity extends CUserIdentity
return !$this->errorCode; return !$this->errorCode;
} }
$manager = Manager::model()->find(array( $manager = Manager::model()->with('access')->find(array(
"select" => array("`id`", "`name`", "`login`"), "select" => array("id", "name", "login"),
"condition" => implode(" AND ", array( "condition" => implode(" AND ", array(
"`manager` = :manager", "manager = :manager",
"`login` = :login", "login = :login",
"`passwd` = :pass" "access.domain = :transport",
"passwd = :pass"
)), )),
"params" => array( "params" => array(
":manager" => 1, ":manager" => 1,
":login" => $this->username, ":login" => $this->getPartOfName($this->username, 'name'),
":transport" => $this->getPartOfName($this->username, 'domain'),
":pass" => $this->password ":pass" => $this->password
) )
)); ));
if($manager===null) { if($manager===null) {
$this->errorCode=self::ERROR_PASSWORD_INVALID; $this->errorCode=self::ERROR_PASSWORD_INVALID;
} }
...@@ -62,4 +64,25 @@ class UserIdentity extends CUserIdentity ...@@ -62,4 +64,25 @@ class UserIdentity extends CUserIdentity
{ {
return $this->_id; return $this->_id;
} }
/**
* Returns part of email name
*/
private function getPartOfName( $param = "", $name = "name")
{
$param = trim($param);
$param = explode("@", $param);
if(count($param) > 2) {
$param = array_slice($param, 0, 2);
}
switch($name) {
case 'name': return $param[0];
case 'domain': return $param[1];
default: return implode("@", $params);
}
}
} }
\ No newline at end of file
...@@ -18,22 +18,6 @@ class UserController extends WRestController ...@@ -18,22 +18,6 @@ class UserController extends WRestController
public function actions() public function actions()
{ {
return array( return array(
'list' => array(
'class' => 'WRestListAction',
'filterBy' => array(
'compare' => array(
'column' => array(
'name' => 'query',
'login' => 'query'
),
'partial' => true,
'operator' => 'OR'
)
),
'limit' => 'limit',
'page' => 'page',
'order' => 'order'
),
'delete' => 'WRestDeleteAction', 'delete' => 'WRestDeleteAction',
'get' => 'WRestGetAction', 'get' => 'WRestGetAction',
'create' => 'WRestCreateAction', 'create' => 'WRestCreateAction',
...@@ -43,4 +27,45 @@ class UserController extends WRestController ...@@ -43,4 +27,45 @@ class UserController extends WRestController
) )
); );
} }
public function actionList()
{
$criteria = new CDbCriteria();
$model = $this->getModel();
$criteria->alias = 'user';
$criteria->limit = (int)(($limit = Yii::app()->request->getParam('limit')) ? $limit : -1);
$page = (int)Yii::app()->request->getParam('page') - 1;
$criteria->offset = ($offset = $limit * $page) ? $offset : 0;
if(($order = Yii::app()->request->getParam("sort")) ? $order : null) {
$order = json_decode($order);
$sort = array();
foreach($order as $item) {
$sort[] = sprintf("user.%s %s", $item->property, $item->direction);
}
$criteria->order = implode(", ", $sort);
}
$models = $model->with('transport')->findAll($criteria);
if ($models) {
foreach ($models as $item) {
$result[] = array_merge($item->getAllAttributes(), array("domain" => $item->transport->domain));
}
}
$result = array_merge($result, array(
'total' => $model->count($criteria)
));
$this->sendResponse(200, $result);
}
} }
...@@ -32,4 +32,16 @@ class Manager extends CActiveRecord ...@@ -32,4 +32,16 @@ class Manager extends CActiveRecord
{ {
return 'id'; return 'id';
} }
public function relations()
{
return array(
"access" => array(
self::HAS_ONE,
"Transport",
array( "id" => "domid" ),
"joinType" => "LEFT JOIN"
)
);
}
} }
...@@ -50,8 +50,8 @@ class Transport extends ActiveRecord ...@@ -50,8 +50,8 @@ class Transport extends ActiveRecord
*/ */
public function rules(){ public function rules(){
return array( return array(
array('domain, transport', 'required', 'on' => 'insert'), array('domain, transport, rootdir', 'required', 'on' => 'insert'),
array('domain, transport', 'required', 'on' => 'update') array('domain, transport, rootdir', 'required', 'on' => 'update')
); );
} }
} }
...@@ -47,19 +47,33 @@ class User extends ActiveRecord ...@@ -47,19 +47,33 @@ class User extends ActiveRecord
/** /**
* Transport relation
*/
public function relations()
{
return array(
"transport" => array(
self::HAS_ONE,
"Transport",
array( "id" => "domid" ),
"joinType" => "LEFT JOIN"
)
);
}
/**
* Model rules * Model rules
*/ */
public function rules() public function rules()
{ {
return array( return array(
array('name, login, passwd, uid, gid, maildir, smtp, imap, quota, manager, backup', 'default', 'on' => 'update'), array('name, login, passwd, uid, gid, domid, smtp, imap, pop3, sieve, quota, manager, backup', 'default', 'on' => 'update'),
array('login, passwd, maildir', 'required', 'on' => 'update'), array('login, passwd, domid', 'required', 'on' => 'update'),
array('smtp, imap, manager', 'numerical', 'on' => 'update', 'allowEmpty' => false, 'integerOnly' => true), array('smtp, imap, pop3, sieve, manager', 'numerical', 'on' => 'update', 'allowEmpty' => false, 'integerOnly' => true),
array('login', 'email', 'on' => 'update'), array('name, login, passwd, uid, gid, domid, smtp, imap, pop3, sieve, quota, manager', 'default', 'on' => 'insert'),
array('name, login, passwd, uid, gid, maildir, smtp, imap, quota, manager', 'default', 'on' => 'insert'), array('login, passwd, domid', 'required', 'on' => 'insert'),
array('login, passwd, maildir', 'required', 'on' => 'insert'), array('smtp, imap, pop3, sieve, domid, manager', 'numerical', 'on' => 'insert', 'allowEmpty' => false, 'integerOnly' => true)
array('smtp, imap, manager', 'numerical', 'on' => 'insert', 'allowEmpty' => false, 'integerOnly' => true),
array('login', 'email', 'on' => 'insert')
); );
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!