Switch from OC::$server->get to OCP\Server::get

And add a bit more typing to some classes + psalm issues

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
This commit is contained in:
Carl Schwan
2022-05-11 11:38:07 +02:00
committed by Julius Härtl
parent 2c7708dab1
commit 44481e1c2a
45 changed files with 1034 additions and 506 deletions

View File

@@ -53,11 +53,12 @@ class AclMapper extends DeckMapper implements IPermissionMapper {
/**
* @param numeric $userId
* @param numeric $aclId
* @param numeric $id
* @return bool
* @throws \OCP\DB\Exception
*/
public function isOwner($userId, $aclId): bool {
public function isOwner($userId, $id): bool {
$aclId = $id;
$qb = $this->db->getQueryBuilder();
$qb->select('acl.id')
->from($this->getTableName(), 'acl')

View File

@@ -77,8 +77,8 @@ class AssignmentMapper extends QBMapper implements IPermissionMapper {
}
public function isOwner($userId, $cardId): bool {
return $this->cardMapper->isOwner($userId, $cardId);
public function isOwner($userId, $id): bool {
return $this->cardMapper->isOwner($userId, $id);
}
public function findBoardId($id): ?int {

View File

@@ -42,9 +42,9 @@ class BoardMapper extends QBMapper implements IPermissionMapper {
private $circlesService;
private $logger;
/** @var CappedMemoryCache */
/** @var CappedMemoryCache<Board[]> */
private $userBoardCache;
/** @var CappedMemoryCache */
/** @var CappedMemoryCache<Board> */
private $boardCache;
public function __construct(
@@ -131,14 +131,9 @@ class BoardMapper extends QBMapper implements IPermissionMapper {
/**
* Find all boards for a given user
*
* @param $userId
* @param null $limit
* @param null $offset
* @return array
*/
public function findAllByUser(string $userId, ?int $limit = null, ?int $offset = null, ?int $since = null,
bool $includeArchived = true, ?int $before = null, ?string $term = null) {
bool $includeArchived = true, ?int $before = null, ?string $term = null): array {
// FIXME this used to be a UNION to get boards owned by $userId and the user shares in one single query
// Is it possible with the query builder?
$qb = $this->db->getQueryBuilder();
@@ -247,15 +242,9 @@ class BoardMapper extends QBMapper implements IPermissionMapper {
/**
* Find all boards for a given user
*
* @param $userId
* @param $groups
* @param null $limit
* @param null $offset
* @return array
*/
public function findAllByGroups(string $userId, array $groups, ?int $limit = null, ?int $offset = null, ?int $since = null,
bool $includeArchived = true, ?int $before = null, ?string $term = null) {
bool $includeArchived = true, ?int $before = null, ?string $term = null): array {
if (count($groups) <= 0) {
return [];
}
@@ -414,8 +403,8 @@ class BoardMapper extends QBMapper implements IPermissionMapper {
return parent::delete($entity);
}
public function isOwner($userId, $boardId): bool {
$board = $this->find($boardId);
public function isOwner($userId, $id): bool {
$board = $this->find($id);
return ($board->getOwner() === $userId);
}

View File

@@ -563,10 +563,10 @@ class CardMapper extends QBMapper implements IPermissionMapper {
$qb->execute();
}
public function isOwner($userId, $cardId): bool {
public function isOwner($userId, $id): bool {
$sql = 'SELECT owner FROM `*PREFIX*deck_boards` WHERE `id` IN (SELECT board_id FROM `*PREFIX*deck_stacks` WHERE id IN (SELECT stack_id FROM `*PREFIX*deck_cards` WHERE id = ?))';
$stmt = $this->db->prepare($sql);
$stmt->bindParam(1, $cardId, \PDO::PARAM_INT, 0);
$stmt->bindParam(1, $id, \PDO::PARAM_INT, 0);
$stmt->execute();
$row = $stmt->fetch();
return ($row['owner'] === $userId);

View File

@@ -24,6 +24,7 @@
namespace OCA\Deck\Db;
use OCP\ICacheFactory;
use OCP\ICache;
use OCP\IDBConnection;
use OCP\IRequest;
@@ -31,13 +32,16 @@ class ChangeHelper {
public const TYPE_BOARD = 'boardChanged';
public const TYPE_CARD = 'cardChanged';
private $db;
private IDBConnection $db;
private ICache $cache;
private IRequest $request;
private ?string $userId;
public function __construct(
IDBConnection $db,
ICacheFactory $cacheFactory,
IRequest $request,
$userId
?string $userId
) {
$this->db = $db;
$this->cache = $cacheFactory->createDistributed('deck_changes');

View File

@@ -129,12 +129,12 @@ class StackMapper extends DeckMapper implements IPermissionMapper {
* @return bool
* @throws \OCP\DB\Exception
*/
public function isOwner($userId, $stackId): bool {
public function isOwner($userId, $id): bool {
$qb = $this->db->getQueryBuilder();
$qb->select('s.id')
->from($this->getTableName(), 's')
->innerJoin('s', 'deck_boards', 'b', 'b.id = s.board_id')
->where($qb->expr()->eq('s.id', $qb->createNamedParameter($stackId, IQueryBuilder::PARAM_INT)))
->where($qb->expr()->eq('s.id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->eq('owner', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)));
return count($qb->executeQuery()->fetchAll()) > 0;