8 namespace Fossology\Lib\Dao;
21 public function __construct(
DbManager $dbManager, Logger $logger)
24 $this->logger = $logger;
27 public function isAccessible($uploadId, $groupId)
29 $perm = $this->
dbManager->getSingleRow(
'SELECT perm FROM perm_upload WHERE upload_fk=$1 AND group_fk=$2',
30 array($uploadId, $groupId), __METHOD__.
'.group_perm');
39 $uploadPub = $this->
dbManager->getSingleRow(
'SELECT public_perm FROM upload WHERE upload_pk=$1 AND public_perm>$2',
41 return !empty($uploadPub);
44 public function isEditable($uploadId, $groupId)
50 $perm = $this->
dbManager->getSingleRow(
'SELECT perm FROM perm_upload WHERE upload_fk=$1 AND group_fk=$2',
51 array($uploadId, $groupId), __METHOD__);
52 if (! empty($perm) && array_key_exists(
'perm', $perm)) {
58 public function makeAccessibleToGroup($uploadId, $groupId, $perm=
null)
63 $this->
dbManager->getSingleRow(
"INSERT INTO perm_upload (perm, upload_fk, group_fk) "
64 .
" VALUES($1,$2,$3)",
65 array($perm, $uploadId, $groupId), __METHOD__);
68 public function makeAccessibleToAllGroupsOf($uploadId, $userId, $perm=
null)
74 $this->
dbManager->getSingleRow(
"INSERT INTO perm_upload (group_fk, perm, upload_fk)
75 SELECT DISTINCT(gum.group_fk), $perm perm, $uploadId upload_fk
76 FROM group_user_member gum
77 LEFT JOIN perm_upload ON perm_upload.group_fk=gum.group_fk
78 AND upload_fk=$uploadId
79 WHERE perm_upload IS NULL AND gum.user_fk=$userId",
80 array(), __METHOD__.
'.insert');
84 public function updatePermissionId($permId, $permLevel)
86 if (empty($permLevel)) {
87 $this->
dbManager->getSingleRow(
'DELETE FROM perm_upload WHERE perm_upload_pk=$1',
89 __METHOD__ .
'.delete');
91 $this->
dbManager->getSingleRow(
'UPDATE perm_upload SET perm=$2 WHERE perm_upload_pk=$1',
92 array($permId, $permLevel),
93 __METHOD__ .
'.update');
97 public function insertPermission($uploadId, $groupId, $permLevel)
99 $this->
dbManager->getSingleRow(
"DELETE FROM perm_upload WHERE upload_fk=$1 AND group_fk=$2",
100 array($uploadId,$groupId),
101 __METHOD__.
'.avoid_doublet');
105 $this->
dbManager->insertTableRow(
'perm_upload', array(
'perm'=>$permLevel,
'upload_fk'=>$uploadId,
'group_fk'=>$groupId));
108 public function setPublicPermission($uploadId, $permLevel)
110 $this->
dbManager->getSingleRow(
'UPDATE upload SET public_perm=$2 WHERE upload_pk=$1', array($uploadId, $permLevel));
113 public function getPublicPermission($uploadId)
115 $row = $this->
dbManager->getSingleRow(
'SELECT public_perm FROM upload WHERE upload_pk=$1 LIMIT 1',array($uploadId),__METHOD__);
116 return $row[
'public_perm'];
119 public function getPermissionGroups($uploadId)
121 $this->
dbManager->prepare($stmt=__METHOD__,
122 "SELECT perm_upload_pk, perm, group_pk, group_name
123 FROM groups, perm_upload
124 WHERE group_fk=group_pk AND upload_fk=$1
125 ORDER BY group_name");
126 $res = $this->
dbManager->execute($stmt, array($uploadId));
128 while ($row=$this->
dbManager->fetchArray($res)) {
129 $groupMap[$row[
'group_pk']] = $row;
Contains the constants and helpers for authentication of user.
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
fo_dbManager * dbManager
fo_dbManager object