/**
  * 静态方法, 单例统一访问入口
  * @return object  返回对象的唯一实例
  */
 public static function getInstance()
 {
     if (is_null(self::$_instance) || !isset(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 public function getUserByDepartmentId($departmentId)
 {
     $userGroups = MiniUserGroupRelation::getInstance()->getByGroupId($departmentId);
     if (count($userGroups) > 0) {
         foreach ($userGroups as $userGroup) {
             $this->ids[] = $userGroup['user_id'];
         }
     }
     $this->getGroups($departmentId);
 }
示例#3
0
 /**
  * 搜索用户
  */
 public function searchFriends($key)
 {
     $userId = $this->user["id"];
     $items = MiniUser::getInstance()->searchByName($userId, $key);
     $users = array();
     foreach ($items as $item) {
         $friend = array();
         $friend["id"] = $item["id"];
         $friend["nick"] = $item["nick"];
         $friend["name"] = $item["user_name"];
         $friend["avatar"] = $item['avatar'];
         $arr = MiniUserGroupRelation::getInstance()->findUserGroup($userId, $item["id"]);
         $friend["user_group"] = $arr;
         array_push($users, $friend);
     }
     return $users;
 }
示例#4
0
 public function getPermission($path, $userId)
 {
     $privilegeLength = 9;
     //权限长度 后期更改则做相应调整
     $userInGroups = MiniUserGroupRelation::getInstance()->getByUserId($userId);
     //用户所在的部门列表,查表user_group_relation
     if (count($userInGroups) > 0) {
         //说明该用户被其他用户分配到其群组中
         //寻找该用户所在的组有无权限,有权限则说明对应的权限有共享文件
         $privilegeArr = array();
         //一个用户同一个被共享文件对应多个群组权限集合
         foreach ($userInGroups as $userInGroup) {
             $groupId = $userInGroup['group_id'];
             $group = MiniGroup::getInstance()->getById($groupId);
             if ($group['user_id'] != -1) {
                 //表示该组为群组
                 $groupPrivilege = MiniGroupPrivilege::getInstance()->getSpecifyPrivilege($groupId, $path);
                 if (!empty($groupPrivilege)) {
                     array_push($privilegeArr, $groupPrivilege);
                 }
             }
         }
         if (count($privilegeArr) > 0) {
             $permission = '';
             for ($i = 0; $i < $privilegeLength; $i++) {
                 foreach ($privilegeArr as $privilege) {
                     $can = false;
                     $value = substr($privilege['permission'], $i, 1);
                     if ($value == '1') {
                         $can = true;
                         break;
                     }
                 }
                 if ($can) {
                     $permission .= '1';
                 } else {
                     $permission .= '0';
                 }
             }
             return $permission;
         }
     }
     return null;
 }
示例#5
0
 /**
  * 存储部门信息,以及用户与部门的关系
  */
 private function saveData($userName, $departmentId)
 {
     $user = MiniUser::getInstance()->getUserByName($userName);
     $userGroupRelations = MiniUserGroupRelation::getInstance()->getByUserId($user['id']);
     $isExist = false;
     //判断用户是否已经被导入,存在则修改
     if (!empty($userGroupRelations)) {
         foreach ($userGroupRelations as $userGroupRelation) {
             $group = MiniGroup::getInstance()->getById($userGroupRelation['group_id']);
             if (!empty($group)) {
                 if ($group['user_id'] > 0) {
                     continue;
                 } else {
                     $isExist = true;
                     break;
                 }
             }
         }
     }
     $group = MiniGroup::getInstance()->findById($departmentId);
     if ($isExist) {
         MiniUserGroupRelation::getInstance()->update($user['id'], $group['id']);
     } else {
         MiniUserGroupRelation::getInstance()->create($user['id'], $group['id']);
     }
 }
示例#6
0
 /**
  * 保存用户权限
  * @param $filePath
  * @param $shareModel
  * @param $slaves
  * @return bool
  */
 public function save($filePath, $shareModel, $slaves)
 {
     $device = MUserManager::getInstance()->getCurrentDevice();
     $userDeviceId = $device["device_id"];
     $this->share_filter = MSharesFilter::init();
     //delete privilege
     $oldGroupPrivileges = MiniGroupPrivilege::getInstance()->getPrivilegeList($filePath);
     $oldUserPrivileges = MiniUserPrivilege::getInstance()->getPrivilegeList($filePath);
     //删除权限
     if (!empty($oldGroupPrivileges)) {
         foreach ($oldGroupPrivileges as $oldGroupPrivilege) {
             $oldGroupId = $oldGroupPrivilege['group_id'];
             $groupExisted = false;
             foreach ($slaves as $groupPrivilege) {
                 $type = $groupPrivilege['type'];
                 if ($type == '1' || $type == '2') {
                     $newGroupId = $groupPrivilege['id'];
                     //todo 原先是($privilege['info']['slave_id']),已修改(2)
                     if ($newGroupId == $oldGroupId) {
                         $groupExisted = true;
                     }
                 }
             }
             if ($groupExisted == false) {
                 //todo 判断的地方有误 导致无法存入数据库(1) 见上(2)
                 MiniGroupPrivilege::getInstance()->deletePrivilege($oldGroupId, $filePath);
             }
         }
     }
     if (!empty($oldUserPrivileges)) {
         foreach ($oldUserPrivileges as $item) {
             $userId = $item['user_id'];
             //数据表中的userId
             $existed = false;
             foreach ($slaves as $userPrivilege) {
                 $type = $userPrivilege['type'];
                 if ($type == '0') {
                     $newUserId = $userPrivilege['id'];
                     //todo 原先是($privilege['info']['slave_id']),已修改(2)
                     if ($newUserId == $userId) {
                         $existed = true;
                     }
                 }
             }
             if ($existed == false) {
                 MiniUserPrivilege::getInstance()->deletePrivilege($userId, $filePath);
             }
         }
     }
     $userIds = array();
     //创建权限
     foreach ($slaves as $privilege) {
         $permission = $privilege['privilege'];
         $privilegeType = $privilege['type'];
         if ($privilegeType == '0') {
             MiniUserPrivilege::getInstance()->create($privilege['id'], $filePath, $permission);
             $userIds[] = $privilege['id'];
         }
         if ($privilegeType == '1') {
             MiniGroupPrivilege::getInstance()->create($privilege['id'], $filePath, $permission);
             $groups = MiniUserGroupRelation::getInstance()->getByGroupId($privilege['id']);
             foreach ($groups as $group) {
                 $userIds[] = $group['user_id'];
             }
         }
         if ($privilegeType == '2') {
             MiniGroupPrivilege::getInstance()->create($privilege['id'], $filePath, $permission);
         }
         $departmentPrivilege = new DepartmentPermissionBiz();
         $departmentPrivilege->getUserByDepartmentId($privilege['id']);
     }
     $ids = array_unique(array_merge($departmentPrivilege->ids, $userIds));
     foreach ($ids as $id) {
         $this->share_filter->slaves[$id] = $id;
     }
     //存储共享模式
     MiniFileMeta::getInstance()->createFileMeta($filePath, "share_model", $shareModel);
     //todo创建共享事件
     $eventAction = MConst::SHARE_FOLDER;
     MiniEvent::getInstance()->createEvent($this->user['id'], $userDeviceId, $eventAction, $filePath, $filePath, MiniUtil::getEventRandomString(MConst::LEN_EVENT_UUID), $this->share_filter->type);
     $this->share_filter->is_shared = true;
     // 为每个共享用户创建事件
     $this->share_filter->handlerAction($eventAction, $userDeviceId, $filePath, $filePath);
     /**
      * 存储权限之后更新被分享文件的file_type = 2,出现分享图标
      */
     MiniFile::getInstance()->updateTime($filePath);
     MiniFile::getInstance()->togetherShareFile($filePath, MConst::OBJECT_TYPE_SHARED);
     return array('success' => true);
 }
示例#7
0
 /**
  * 用户与群组解绑
  */
 public function unbind($userId, $groupId)
 {
     return MiniUserGroupRelation::getInstance()->unbind($userId, $groupId);
 }
示例#8
0
 /**
  * 获取目录树
  * @param $parentGroupId
  * @param bool $showUser
  * @return array
  */
 public function getTreeNodes($parentGroupId, $showUser = true)
 {
     $relations = MiniGroupRelation::getInstance()->getByParentId($parentGroupId);
     $userRelations = MiniUserGroupRelation::getInstance()->getByGroupId($parentGroupId);
     if (isset($relations)) {
         foreach ($relations as $relation) {
             $group = $this->getById($relation['group_id']);
             $newGroup[] = $group['id'];
             $newGroup[] = $group['group_name'];
             $groups[] = $group;
         }
     }
     if (0 < count($groups)) {
         for ($i = 0; $i < count($groups); $i++) {
             $groups[$i]['nodes'] = $this->getTreeNodes($groups[$i]['id'], $showUser);
             if ($groups[$i]['nodes'] == NULL) {
                 $groups[$i]['nodes'] = array();
             }
         }
     }
     if ($showUser) {
         if ($userRelations) {
             foreach ($userRelations as $userRelation) {
                 $user = array();
                 $userInfo = MiniUser::getInstance()->getById($userRelation['user_id']);
                 $user['id'] = $userInfo['id'];
                 $user['user_name'] = $userInfo['nick'];
                 $user['group_id'] = $parentGroupId;
                 $groups[] = $user;
             }
         }
     }
     return $groups;
 }
示例#9
0
 /**
  * 判断目录是否可发起共享
  * 递归查询父目录file_type情况,file_type=1时返回false,file_type==2||3时返回true
  */
 public function getFolderPrivilege($currentUserId, $file)
 {
     $filePath = $file['file_path'];
     $fileType = (int) $file['file_type'];
     //被共享目录本身可以修改和删除
     $privilege = array('resource.read' => 1, 'folder.create' => 1, 'folder.rename' => 1, 'folder.delete' => 1, 'file.create' => 1, 'file.modify' => 1, 'file.rename' => 1, 'file.delete' => 1, 'permission.grant' => 1, 'can_set_share' => 1);
     if ($fileType == 3) {
         $parentPath = $file['file_path'];
         //当用户,群组与部门中的用户权限出现重复时,获取最小部门的权限,顺序为用户,群组,部门
         $userPrivilege = MiniUserPrivilege::getInstance()->getSpecifyPrivilege($currentUserId, $parentPath);
         if (empty($userPrivilege)) {
             $userGroupRelations = MiniUserGroupRelation::getInstance()->getByUserId($currentUserId);
             if (count($userGroupRelations) > 1) {
                 //说明用户对应了群组和部门,
                 $groupIdsArr = array();
                 //获取群组id
                 foreach ($userGroupRelations as $userGroupRelation) {
                     $group = MiniGroup::getInstance()->findById($userGroupRelation['group_id']);
                     if ($group['user_id'] != -1) {
                         array_push($groupIdsArr, $userGroupRelation['group_id']);
                     } else {
                         $departmentId = $userGroupRelation['group_id'];
                     }
                 }
                 //将所有群组的权限放入数组
                 $permissionArr = array();
                 foreach ($groupIdsArr as $groupId) {
                     $privilege_0 = MiniGroupPrivilege::getInstance()->getSpecifyPrivilege($groupId, $parentPath);
                     if (!empty($privilege_0)) {
                         array_push($permissionArr, $privilege_0['permission']);
                     }
                 }
                 //拼接群组中权限的最大值,如果为空则为空字符串
                 $permission = "";
                 if (count($permissionArr) > 0) {
                     for ($j = 0; $j < 10; $j++) {
                         $isHighestAuthority = false;
                         foreach ($permissionArr as $per) {
                             if ($per[$j] == 1) {
                                 $isHighestAuthority = true;
                                 break;
                             }
                         }
                         if ($isHighestAuthority) {
                             $permission .= "1";
                         } else {
                             $permission .= "0";
                         }
                     }
                 }
                 if ($permission == "") {
                     $groupPrivilege = MiniGroupPrivilege::getInstance()->getSpecifyPrivilege($departmentId, $parentPath);
                     if (empty($groupPrivilege)) {
                         $groupPrivilege = MiniGroupPrivilege::getInstance()->getGroupPrivilege($filePath, $departmentId);
                     }
                     $permission = $groupPrivilege['permission'];
                 }
             } else {
                 $groupId = $userGroupRelations[0]['group_id'];
                 $groupPrivilege = MiniGroupPrivilege::getInstance()->getSpecifyPrivilege($groupId, $parentPath);
                 if (empty($groupPrivilege)) {
                     $groupPrivilege = MiniGroupPrivilege::getInstance()->getGroupPrivilege($filePath, $groupId);
                 }
                 $permission = $groupPrivilege['permission'];
             }
         } else {
             $permission = $userPrivilege['permission'];
         }
         for ($i = 0; $i < strlen($permission); $i++) {
             $privilege['resource.read'] = (int) $permission[0];
             $privilege['folder.create'] = (int) $permission[1];
             $privilege['folder.rename'] = (int) $permission[2];
             $privilege['folder.delete'] = (int) $permission[3];
             $privilege['file.create'] = (int) $permission[4];
             $privilege['file.modify'] = (int) $permission[5];
             $privilege['file.rename'] = (int) $permission[6];
             $privilege['file.delete'] = (int) $permission[7];
             $privilege['permission.grant'] = (int) $permission[8];
             $privilege["can_set_share"] = 0;
         }
     }
     if ($fileType == 1) {
         $isShared = false;
         $userId = $file['user_id'];
         //判断下级目录是否有共享目录
         $filePath = $file['file_path'];
         $children = MiniFile::getInstance()->getShowChildrenByPath($currentUserId, $filePath);
         $userGroupRelation = MiniUserGroupRelation::getInstance()->getByUserId($userId);
         $groupId = $userGroupRelation['group_id'];
         $arr = array();
         array_push($arr, $groupId);
         foreach ($children as $child) {
             $childFilePath = $child['file_path'];
             if ($childFilePath == $filePath) {
                 continue;
             }
             $file = MiniFile::getInstance()->getByFilePath($childFilePath);
             if ($file['file_type'] == 2) {
                 $isShared = true;
                 break;
             }
         }
         if ($isShared) {
             //子目录已经共享则不能二次共享
             $privilege["can_set_share"] = 0;
         } else {
             //判断上级目录是否有共享目录
             $arr = explode('/', $filePath);
             $parentPath = "/" . $userId;
             for ($i = 2; $i < count($arr); $i++) {
                 $parentPath = $parentPath . "/" . $arr[$i];
                 $file = MiniFile::getInstance()->getByFilePath($parentPath);
                 if ($file['file_type'] == 2) {
                     $privilege["can_set_share"] = 0;
                 }
             }
         }
     }
     return $privilege;
 }
示例#10
0
 /**
  *
  * 删除用户相关信息
  * @userIds 用户列表{1,2,3,4,5}这样的格式
  */
 public function deleteUsers($userIds)
 {
     if ($userIds != '' && strlen($userIds) > 0) {
         $ids = explode(',', $userIds);
         $userFile = new UserFile();
         foreach ($ids as $id) {
             // 删除用户共享文件
             $userFile->deleteSharedFolders($id);
             //删除所有标签信息
             Tag::model()->deleteUserAllTag($id);
             //删除我的最爱文件
             FileStar::model()->deleteUserAllStar($id);
         }
         //删除用户的文件信息
         $userFile->deleteUserFile($userIds);
         //删除用户的群组部门关系
         MiniUserGroupRelation::getInstance()->deleteUserRelation($userIds);
         //删除用户的事件信息
         MiniEvent::getInstance()->deleteByIds($userIds);
         //删除用户Meta以及用户自己
         foreach ($ids as $id) {
             //删除用户自身
             MiniUser::getInstance()->deleteUser($id);
         }
     }
 }
示例#11
0
 public function getAllSharedPath($userId)
 {
     $userPrivileges = MiniUserPrivilege::getInstance()->getByUserId($userId);
     $filePaths = array();
     foreach ($userPrivileges as $userPrivilege) {
         array_push($filePaths, $userPrivilege['file_path']);
     }
     $groupPrivileges = MiniGroupPrivilege::getInstance()->getAllGroups();
     $publicPrivileges = MiniGroupPrivilege::getInstance()->getPublic();
     foreach ($publicPrivileges as $publicPrivilege) {
         array_push($filePaths, $publicPrivilege['file_path']);
     }
     $groupIds = array();
     foreach ($groupPrivileges as $groupPrivilege) {
         array_push($groupIds, $groupPrivilege['group_id']);
     }
     $groupIdsArr = array();
     $userGroupRelations = MiniUserGroupRelation::getInstance()->findUserGroup($userId);
     if (isset($userGroupRelations)) {
         foreach ($userGroupRelations as $userRelation) {
             $groupId = $userRelation['id'];
             $arr = array();
             array_push($arr, $groupId);
             $result = MiniGroup::getInstance()->findById($groupId);
             if ($result['user_id'] > 0) {
                 array_push($groupIdsArr, $groupId);
             } else {
                 $ids = $this->getGroupIds($groupId, $arr);
             }
         }
         array_splice($groupIdsArr, 0, 0, $ids);
         $commonGroupIds = array_merge($groupIdsArr, $groupIds);
         foreach ($commonGroupIds as $commonGroupId) {
             $groupInfos = MiniGroupPrivilege::getInstance()->getByGroupId($commonGroupId);
             foreach ($groupInfos as $groupInfo) {
                 $paths[] = $groupInfo['file_path'];
             }
         }
         if ($paths) {
             array_splice($filePaths, 0, 0, $paths);
         }
     }
     $paths = array();
     $filePaths = array_unique($filePaths);
     foreach ($filePaths as $filePath) {
         $result = MiniFile::getInstance()->getByPath($filePath);
         if (count($result) == 0) {
             continue;
         }
         //当共享文件为共享者的时候进行过滤
         $arr = explode("/", $filePath);
         $userId = $this->user['id'];
         $slaveId = $arr[1];
         if ($slaveId == $userId) {
             continue;
         }
         $fileBiz = new FileBiz();
         $canRead = $fileBiz->privilege($filePath);
         if (!$canRead) {
             continue;
         }
         $paths[] = $filePath;
     }
     return $paths;
 }
示例#12
0
 public function saveUser($item, $departmentId)
 {
     $errorCount = 0;
     $errorName = array();
     for ($i = 1; $i < count($item); $i++) {
         if (strlen(trim($item[$i])) == 0) {
             continue;
         }
         $user = MiniUser::getInstance()->getUserByName($item[$i]);
         if (empty($user)) {
             $errorCount++;
             $errorName[] = $item[$i];
             continue;
         }
         $userGroupRelations = MiniUserGroupRelation::getInstance()->getByUserId($user['id']);
         $isExist = false;
         //判断用户是否已经被导入,存在则修改
         if (!empty($userGroupRelations)) {
             foreach ($userGroupRelations as $userGroupRelation) {
                 $group = MiniGroup::getInstance()->getById($userGroupRelation['group_id']);
                 if (!empty($group)) {
                     if ($group['user_id'] > 0) {
                         continue;
                     } else {
                         $isExist = true;
                         break;
                     }
                 }
             }
         }
         $group = MiniGroup::getInstance()->findById($departmentId);
         if ($isExist) {
             MiniUserGroupRelation::getInstance()->update($user['id'], $group['id']);
         } else {
             MiniUserGroupRelation::getInstance()->create($user['id'], $group['id']);
         }
     }
     if ($errorCount > 0) {
         $data[] = "该用户不存在,您可以先导入用户,再进行添加";
         $data[] = $item[0];
         $data[] = $errorName;
         $this->errorList[] = $data;
     }
 }