v0.93 users & permissions mod

Hi, I made a small mod on the users_model.php.

I have some requirements that the normal FUEL CMS release doesn't provide, I want to give to my customer the ability to create users (employees) with equal or less permissions that he has, on normal v0.93 release I can only do this giving permissions permission, so he can create, delete, and modify permissions, he can also create a user with more permissions than he has :P LOL , so I made this mod.

The normal user, having users permission, can create users with equal or less permissions without the need of having permissions permission.
Users permissions can only be saw by different user.
Only super users or users with permissions permission can see and edit all permissions.

function form_fields($values = null) { $CI = & get_instance(); $CI->load->helper('directory'); $fields = parent::form_fields(); unset($fields['super_admin']); // save reference it so we can reorder $pwd_field = $fields['password']; unset($fields['password']); $user_id = NULL; if (!empty($values['id'])) { $user_id = $values['id']; } if (!empty($user_id)) { $fields['new_password'] = array('label' => lang('form_label_new_password'), 'type' => 'password', 'size' => 20, 'order' => 5); } else { $pwd_field['type'] = 'password'; $pwd_field['size'] = 20; $pwd_field['order'] = 5; $fields['password'] = $pwd_field; } $lang_dirs = list_directories(FUEL_PATH . 'language/', array(), FALSE); $lang_options = array_combine($lang_dirs, $lang_dirs); if (count($lang_options) >= 2) { $fields['language'] = array('type' => 'select', 'options' => $lang_options, 'value' => 'english'); } else { $fields['language']['type'] = 'hidden'; } $fields['user_name']['order'] = 1; $fields['email']['order'] = 2; $fields['first_name']['order'] = 3; $fields['last_name']['order'] = 4; $fields['confirm_password'] = array('label' => lang('form_label_confirm_password'), 'type' => 'password', 'size' => 20, 'order' => 6); $fields['active']['order'] = 8; // get permissions $CI = & get_instance(); $perm_fields = array(); $user = $CI->fuel_auth->user_data(); //Modified by Pedro Simões if (($user['id'] != $user_id) OR (!$CI->fuel_auth->is_super_admin() AND $CI->fuel_auth->has_permission('permissions'))) { $CI->load->module_model(FUEL_FOLDER, 'user_to_permissions_model'); $selected_perms = $CI->user_to_permissions_model->get_permissions($user_id, FALSE); $fields[lang('permissions_heading')] = array('type' => 'section', 'order' => 10); $CI->load->module_model(FUEL_FOLDER, 'permissions_model'); if ($CI->fuel_auth->is_super_admin() || $CI->fuel_auth->has_permission('permissions')) { $perms = $CI->permissions_model->find_all_array(array('active' => 'yes'), 'name asc'); } else { $editor_permissions = $CI->user_to_permissions_model->get_permissions($user['id'], FALSE); $perms = Array(); foreach ($editor_permissions as $val) { $perms = array_merge($perms, $CI->permissions_model->find_all_array(array('id' => $val['perm_id']))); } } $order = 11; foreach ($perms as $val) { $perm_field = 'permissions_' . $val['id']; $perm_fields[$perm_field]['type'] = 'checkbox'; $perm_fields[$perm_field]['value'] = $val['id']; $perm_fields[$perm_field]['order'] = $order; $label = lang('perm_' . $val['name']); if (empty($label)) { $label = (!empty($val['description'])) ? $val['description'] : $val['name']; } $perm_fields[$perm_field]['label'] = $label; if (!empty($selected_perms[$val['id']])) $perm_fields[$perm_field]['checked'] = TRUE; $order++; } } //Modified end $fields = array_merge($fields, $perm_fields); unset($fields['reset_key']); return $fields; }


  • edited 7:41PM
    Great idea. I've never felt comfortable with the current implementation of user/permissions and this seems to help a lot. I've made that change to the 1.0 beta branch that we are working on. If you are interested, I'd recommend checking out 1.0 and taking it for a spin:
  • edited 7:41PM
    I'm happy to help, FUEL CMS it's the best CMS I have found, it gives a great platform to develop my own modules. :)
    I already checked out 1.0, and I saw some fields named 'language', do you have plans to support multiple languages?
    My solution for multiple languages was to create a languages model, and linking it to my custom modules, on native modules (pages) I created a layout for each language and a navigation group for each language, it's not the best solution, but it's the best that I found without great modifications to the v0.93 platform, and in short time.

    Thanks, Pedro Simões.
  • edited 7:41PM
    FUEL 1.0 does support multiple languages. In your MY_fuel.php file, there is a "language" parameter in which you can add to. Having more then one will give you a language dropdown when creating a page. For simple modules, if you have a field of "language" in your model, it will automatically show a language dropdown in the list view (the field name is configurable too).

    For displaying on the front end, you can use the Fuel_language class to detect and set the language to be displayed on the front end:
    // to set $this->fuel->language->set_selected('spanish'); ... // to detect in order of query string, cookie, user agent $lang = $this->fuel->language->detect(); // or $lang = $this->fuel->language->selected();
  • edited 7:41PM
    I will test it, thanks. :)
Sign In or Register to comment.