本文整理汇总了PHP中Permission类的典型用法代码示例。如果您正苦于以下问题:PHP Permission类的具体用法?PHP Permission怎么用?PHP Permission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Permission类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processRecord
public function processRecord($record, $columnMap, &$results, $preview = false)
{
// We match by 'Code', the ID property is confusing the importer
if (isset($record['ID'])) {
unset($record['ID']);
}
$objID = parent::processRecord($record, $columnMap, $results, $preview);
$group = DataObject::get_by_id($this->objectClass, $objID);
// set group hierarchies - we need to do this after all records
// are imported to avoid missing "early" references to parents
// which are imported later on in the CSV file.
if (isset($record['ParentCode']) && $record['ParentCode']) {
$parentGroup = DataObject::get_one('Group', array('"Group"."Code"' => $record['ParentCode']));
if ($parentGroup) {
$group->ParentID = $parentGroup->ID;
$group->write();
}
}
// set permission codes - these are all additive, meaning
// existing permissions arent cleared.
if (isset($record['PermissionCodes']) && $record['PermissionCodes']) {
foreach (explode(',', $record['PermissionCodes']) as $code) {
$p = DataObject::get_one('Permission', array('"Permission"."Code"' => $code, '"Permission"."GroupID"' => $group->ID));
if (!$p) {
$p = new Permission(array('Code' => $code));
$p->write();
}
$group->Permissions()->add($p);
}
}
return $objID;
}
示例2: run
public function run()
{
if (file_exists(app_path() . '/config/creds.yml')) {
$creds = yaml_parse_file(app_path() . '/config/creds.yml');
} else {
$creds = array('admin_email' => 'admin@example.com');
}
$admin = new Role();
$admin->name = 'Admin';
$admin->save();
$independent_sponsor = new Role();
$independent_sponsor->name = 'Independent Sponsor';
$independent_sponsor->save();
$permIds = array();
foreach ($this->adminPermissions as $permClass => $data) {
$perm = new Permission();
foreach ($data as $key => $val) {
$perm->{$key} = $val;
}
$perm->save();
$permIds[] = $perm->id;
}
$admin->perms()->sync($permIds);
$user = User::where('email', '=', $creds['admin_email'])->first();
$user->attachRole($admin);
$createDocPerm = new Permission();
$createDocPerm->name = "independent_sponsor_create_doc";
$createDocPerm->display_name = "Independent Sponsoring";
$createDocPerm->save();
$independent_sponsor->perms()->sync(array($createDocPerm->id));
}
示例3: __invoke
public function __invoke(Permission $acl, $role, $resource, $privilege)
{
if (!$this->publiclySharedFiles) {
$this->init();
}
return in_array($acl->getQueriedResource()->id, $this->publiclySharedFiles);
}
示例4: createPermissions
function createPermissions($meta, $moduleId)
{
$permData = $meta->permissions;
if (empty($permData)) {
return;
}
foreach ($permData as $key => $val) {
if (!empty($val)) {
foreach ($val as $permissionString => $defaultValue) {
$permissionObj = new Permission();
$permissionObj->Load("user_level = ? and module_id = ? and permission = ?", array($key, $moduleId, $permissionString));
if (empty($permissionObj->id) && $permissionObj->module_id == $moduleId) {
} else {
$permissionObj = new Permission();
$permissionObj->user_level = $key;
$permissionObj->module_id = $moduleId;
$permissionObj->permission = $permissionString;
$permissionObj->value = $defaultValue;
$permissionObj->meta = '["value", {"label":"Value","type":"select","source":[["Yes","Yes"],["No","No"]]}]';
$permissionObj->Save();
}
}
}
}
}
示例5: run
public function run()
{
$adminEmail = Config::get('madison.seeder.admin_email');
$admin = new Role();
$admin->name = 'Admin';
$admin->save();
$independent_sponsor = new Role();
$independent_sponsor->name = 'Independent Sponsor';
$independent_sponsor->save();
$permIds = array();
foreach ($this->adminPermissions as $permClass => $data) {
$perm = new Permission();
foreach ($data as $key => $val) {
$perm->{$key} = $val;
}
$perm->save();
$permIds[] = $perm->id;
}
$admin->perms()->sync($permIds);
$user = User::where('email', '=', $adminEmail)->first();
$user->attachRole($admin);
$createDocPerm = new Permission();
$createDocPerm->name = "independent_sponsor_create_doc";
$createDocPerm->display_name = "Independent Sponsoring";
$createDocPerm->save();
$independent_sponsor->perms()->sync(array($createDocPerm->id));
}
示例6: run
public function run()
{
$ver_usuarios = new Permission();
$ver_usuarios->name = 'ver_usuarios';
$ver_usuarios->display_name = 'ver usuarios';
$ver_usuarios->save();
$ver_roles = new Permission();
$ver_roles->name = 'ver_roles';
$ver_roles->display_name = 'ver roles';
$ver_roles->save();
$crear_roles = new Permission();
$crear_roles->name = 'crear_roles';
$crear_roles->display_name = 'crear roles';
$crear_roles->save();
$crear_usuarios = new Permission();
$crear_usuarios->name = 'crear_usuarios';
$crear_usuarios->display_name = 'crear usuarios';
$crear_usuarios->save();
$editar_roles = new Permission();
$editar_roles->name = 'editar_roles';
$editar_roles->display_name = 'editar roles';
$editar_roles->save();
$editar_usuarios = new Permission();
$editar_usuarios->name = 'editar_usuarios';
$editar_usuarios->display_name = 'editar usuarios';
$editar_usuarios->save();
$eliminar_usuarios = new Permission();
$eliminar_usuarios->name = 'eliminar_usuarios';
$eliminar_usuarios->display_name = 'eliminar usuarios';
$eliminar_usuarios->save();
$eliminar_roles = new Permission();
$eliminar_roles->name = 'eliminar_roles';
$eliminar_roles->display_name = 'eliminar roles';
$eliminar_roles->save();
}
示例7: save
public function save($id = FALSE)
{
if ($_POST) {
$user_type = new User_type($id);
$user_type->from_array($_POST);
$user_type->save();
foreach ($user_type->permission as $item) {
$item->delete();
}
if (isset($_POST['checkbox'])) {
foreach ($_POST['checkbox'] as $module => $item) {
$data['user_type_id'] = $user_type->id;
$data['module'] = $module;
foreach ($item as $perm => $val) {
$data[$perm] = $val;
}
$permission = new Permission();
$permission->from_array($data);
$permission->save();
$data = array();
}
}
set_notify('success', lang('save_data_complete'));
}
//redirect('permissions/admin/permissions');
redirect($_SERVER['HTTP_REFERER']);
}
示例8: equals
public function equals(Permission $permission)
{
if ($permission->getName() != $this->name) {
return false;
}
// True if allow is equal ((true && true) || (false && false))
return !($this->isAllowed() xor $permission->isAllowed());
}
示例9: factory
public static function factory($id = null)
{
$instance = new Permission();
if (!empty($id)) {
$instance->where('id', $id)->get();
}
return $instance;
}
示例10: _savePermissions
function _savePermissions($setting_values)
{
$newGroup = new Permission($this->dbcon);
foreach ($setting_values as $perid) {
$newGroup->dropID();
$newGroup->setData(array('perid' => $perid, 'groupid' => $this->id));
$newGroup->save();
}
}
示例11: addPermission
function addPermission($permissionCfg)
{
// verify obligatory fields
if (!$permissionCfg->name) {
throw new Exception('Permission name must be set');
}
if (is_null($permissionCfg->partnerId) || $permissionCfg->partnerId === '') {
throw new Exception('Permission partner id must be set');
}
// init new db permission object
$permission = new Permission();
foreach ($permissionCfg as $key => $value) {
$setterCallback = array($permission, "set{$key}");
call_user_func_array($setterCallback, array($value));
}
if (!$permission->getFriendlyName()) {
$permission->setFriendlyName($permission->getName());
}
if (!$permission->getStatus()) {
$permission->setStatus(PermissionStatus::ACTIVE);
}
// add to database
KalturaLog::log('Adding new permission with name [' . $permission->getName() . '] to partner id [' . $permission->getPartnerId() . ']');
try {
PermissionPeer::addToPartner($permission, $permission->getPartnerId());
} catch (kPermissionException $e) {
if ($e->getCode() === kPermissionException::PERMISSION_ALREADY_EXISTS) {
KalturaLog::log('Permission name [' . $permission->getName() . '] already exists for partner id [' . $permission->getPartnerId() . ']');
} else {
throw $e;
}
}
}
示例12: store
/**
* Store a newly created resource in storage.
* POST /permissions
*
* @return Response
*/
public function store()
{
$permission = new Permission();
$permission->name = Input::get('name');
$permission->display_name = Input::get('display_name');
if ($permission->save()) {
return Redirect::back()->with('permissions-notice', '"' . Input::get('display_name') . '" has been created.');
} else {
return Redirect::back()->with('permissions-errors', $permission->errors());
}
}
示例13: run
public function run()
{
/**
* ------------------------ Role Definitions ------------------------
*/
$admin = new Role();
$admin->name = 'administrator';
$admin->display_name = 'Administrator';
$admin->description = 'master admin';
$admin->save();
$user = new Role();
$user->name = 'user';
$user->display_name = 'User';
$user->description = 'Generic user';
$user->save();
/**
* --------------------- Permission Definitions ---------------------
*/
$editAllPosts = new Permission();
$editAllPosts->name = 'edit_all_posts';
$editAllPosts->display_name = 'Can Edit All Posts';
$editAllPosts->description = 'permission for the master admin to be able to edit all posts';
$editAllPosts->save();
$editAllUsers = new Permission();
$editAllUsers->name = 'edit_all_users';
$editAllUsers->display_name = 'Can Edit All Users';
$editAllUsers->description = 'Able to edit all user profiles and information';
$editAllUsers->save();
$editAllRoles = new Permission();
$editAllRoles->name = 'edit_all_roles';
$editAllRoles->display_name = 'Can Edit All Roles';
$editAllRoles->description = 'Able to add or remove any role for any user';
$editAllRoles->save();
$editOwnPosts = new Permission();
$editOwnPosts->name = 'edit_own_posts';
$editOwnPosts->display_name = 'Can Edit Own Posts';
$editOwnPosts->description = 'Users can edit their own posts';
$editOwnPosts->save();
$editOwnProfile = new Permission();
$editOwnProfile->name = 'edit_own_profile';
$editOwnProfile->display_name = 'Can Edit Own Profile';
$editOwnProfile->description = 'Users can edit their own profiles';
$editOwnProfile->save();
$createPost = new Permission();
$createPost->name = 'create_post';
$createPost->display_name = 'Can Create Post';
$createPost->description = 'Able to create a post';
$createPost->save();
/**
* ----------------------- Attatch Permissions -----------------------
*/
$admin->attatchPermissions([$editAllPosts, $editAllUsers, $editAllRoles, $editOwnPosts, $editOwnProfile, $createPost]);
$user->attatchPermissions([$editOwnPosts, $editOwnProfile, $createPost]);
}
示例14: loadTemplateSafelyByPermission
/**
* Load a given view if the logged user have the required permission
* @param $requiredPermission - String with the permission route required to access the asked view
* @param $template - String with the view to be loaded
* @param $data - Data to pass along the view
*/
function loadTemplateSafelyByPermission($requiredPermission, $template, $data = array())
{
$permission = new Permission();
$ci = get_instance();
$userHasPermission = $permission->checkUserPermission($requiredPermission);
if ($userHasPermission) {
$ci->load->template($template, $data);
} else {
logoutUser();
}
}
示例15: implies
public function implies(Permission $p)
{
if ($p instanceof BasicPermission) {
// This has to be changed to do a wildcard match
if ($p->getName() == $this->getName()) {
return true;
}
return false;
}
return false;
}