<?php
+namespace IPF\Auth\Admin;
+
+use \IPF\Auth\Role as Role;
+use \IPF\Auth\Permission as Permission;
use \PFF\HtmlBuilder\Text as Text;
function permissionChoices()
$choices = array();
foreach (Permission::query()->fetchAll() as $p) {
list($appSlug, $componentSlug, $permission) = explode('|', $p->name);
- $component = IPF_Admin_App::getComponentBySlugs($appSlug, $componentSlug);
+ $component = \IPF_Admin_App::getComponentBySlugs($appSlug, $componentSlug);
if ($component)
$title = $component->app->getTitle().' | '.$component->verbose_name().' | '.ucfirst($permission);
return $choices;
}
-class IPFAuthAdminUserForm extends IPF_ObjectForm
+class UserForm extends \IPF_ObjectForm
{
private $isAdd;
{
$this->isAdd = $extra['is_add'];
- $this->fields['username'] = new IPF_Form_Field_Varchar(array(
+ $this->fields['username'] = new \IPF_Form_Field_Varchar(array(
'required' => true,
'max_length' => 32,
'label' => __('Username'),
'help_text' => __('Required. 32 characters or less. Alphanumeric characters only (letters, digits and underscores).'),
));
- $this->fields['password1'] = new IPF_Form_Field_Varchar(array(
+ $this->fields['password1'] = new \IPF_Form_Field_Varchar(array(
'label' => __('Password'),
'required' => $this->isAdd,
'max_length' => 32,
'widget' => 'IPF_Form_Widget_PasswordInput'
));
- $this->fields['password2'] = new IPF_Form_Field_Varchar(array(
+ $this->fields['password2'] = new \IPF_Form_Field_Varchar(array(
'label' => __('Password (again)'),
'required' => $this->isAdd,
'max_length' => 32,
'help_text' => __('Enter the same password as above, for verification.'),
));
- $this->fields['email'] = new IPF_Form_Field_Email(array(
+ $this->fields['email'] = new \IPF_Form_Field_Email(array(
'required' => true,
'max_length' => 200,
'label' => __('E-mail'),
));
- $this->fields['is_active'] = new IPF_Form_Field_Boolean(array(
+ $this->fields['is_active'] = new \IPF_Form_Field_Boolean(array(
'label' => __('Active'),
'help_text' => __('Designates whether this user should be treated as active. Unselect this instead of deleting accounts.'),
));
- $this->fields['is_staff'] = new IPF_Form_Field_Boolean(array(
+ $this->fields['is_staff'] = new \IPF_Form_Field_Boolean(array(
'label' => __('Staff status'),
'help_text' => __('Designates whether the user can log into this admin site.'),
));
- $this->fields['is_superuser'] = new IPF_Form_Field_Boolean(array(
+ $this->fields['is_superuser'] = new \IPF_Form_Field_Boolean(array(
'label' => __('Superuser status'),
'help_text' => __('Designates that this user has all permissions without explicitly assigning them.'),
));
$permissions = array('is_active', 'is_staff', 'is_superuser');
- if (IPF_Auth_App::ArePermissionsEnabled()) {
+ if (\IPF_Auth_App::ArePermissionsEnabled()) {
$permissions[] = 'permissions';
$permissions[] = 'roles';
- $this->fields['permissions'] = new IPF_Form_Field_MultipleChoice(array(
+ $this->fields['permissions'] = new \IPF_Form_Field_MultipleChoice(array(
'label' => __('Permissions'),
'choices' => permissionChoices(),
'widget' => 'IPF_Form_Widget_SelectMultipleInputCheckbox',
'widget_attrs' => array('class' => 'checkgroup'),
));
- $this->fields['roles'] = new IPF_Form_Field_MultipleChoice(array(
+ $this->fields['roles'] = new \IPF_Form_Field_MultipleChoice(array(
'label' => __('Groups'),
'help_text' => __('In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in.'),
'choices' => Role::query()->fetchPairs('name', 'id'),
}
}
-class AdminUser extends IPF_Admin_Component
+class AdminUser extends \IPF_Admin_Component
{
private $auth_app;
'is_staff',
'is_superuser',
);
- if (IPF_Auth_App::ArePermissionsEnabled()) {
+ if (\IPF_Auth_App::ArePermissionsEnabled()) {
$columns[] = 'groups';
}
return $columns;
} else {
$extra['is_add'] = true;
}
- return new IPFAuthAdminUserForm($data, $user, $extra);
+ return new UserForm($data, $user, $extra);
}
public function saveObject($form, $user)
protected function objectTools($user)
{
return array(
- 'impersonate' => IPF_HTTP_URL::urlForView('IPF_Admin_Views_Impersonate', array($user->id)),
+ 'impersonate' => \IPF_HTTP_URL::urlForView('IPF_Admin_Views_Impersonate', array($user->id)),
);
}
public function verbose_name() { return __('User'); }
+ public function slug() { return 'user'; }
}
-class IPFAdminRoleForm extends IPF_ObjectForm
+class RoleForm extends \IPF_ObjectForm
{
function initFields($extra=array())
{
- $this->fields['name'] = new IPF_Form_Field_Varchar(array(
+ $this->fields['name'] = new \IPF_Form_Field_Varchar(array(
'required' => true,
'label' => __('Name'),
'max_length' => 255,
));
- if (IPF_Auth_App::ArePermissionsEnabled()) {
- $this->fields['permissions'] = new IPF_Form_Field_MultipleChoice(array(
+ if (\IPF_Auth_App::ArePermissionsEnabled()) {
+ $this->fields['permissions'] = new \IPF_Form_Field_MultipleChoice(array(
'label' => __('Permissions'),
'choices' => permissionChoices(),
'widget' => 'IPF_Form_Widget_SelectMultipleInputCheckbox',
}
}
-class AdminRole extends IPF_Admin_Component
+class AdminRole extends \IPF_Admin_Component
{
public function getItems($searchValue, $filters, $page, $pageSize)
{
protected function _getForm($role, $data)
{
if ($role)
- return new IPFAdminRoleForm($data, $role, array('initial' => array(
+ return new RoleForm($data, $role, array('initial' => array(
'permissions' => \PFF\Arr::create($role->permissions())->pluck('id')->arr(),
)));
else
- return new IPFAdminRoleForm($data, null);
+ return new RoleForm($data, null);
}
public function saveObject($form, $role)
$role->save();
Permission::revokeAll($role);
- foreach (Permission::query()->where('id', $form->cleaned_data['permissions']) as $permission)
- $permission->grant($role);
+ $permissions = Permission::query()->where('id', $form->cleaned_data['permissions'])->fetchAll();
+ Permission::grantAll($permissions, $role);
return array($role->id, $role);
}
public function page_title() { return __('Role'); }
public function verbose_name() { return __('Role'); }
+ public function slug() { return 'role'; }
}
-if (IPF_Auth_App::ArePermissionsEnabled()) {
+if (\IPF_Auth_App::ArePermissionsEnabled()) {
return array(
- 'AdminUser',
- 'AdminRole',
+ 'IPF\Auth\Admin\AdminUser',
+ 'IPF\Auth\Admin\AdminRole',
);
} else {
return array(
- 'AdminUser',
+ 'IPF\Auth\Admin\AdminUser',
);
}