From 3d305426999e54ebac49ac576639d22e0f95160b Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Sat, 21 Sep 2024 16:46:23 +0200 Subject: [PATCH] rename all necessary columns Signed-off-by: Julien Veyssier --- appinfo/info.xml | 2 +- lib/Controller/ApiController.php | 3 +- lib/Controller/PublicApiController.php | 4 +- lib/Db/BillMapper.php | 49 ++--- lib/Db/BillOwer.php | 20 +- lib/Db/BillOwerMapper.php | 4 +- lib/Db/Category.php | 10 +- lib/Db/CategoryMapper.php | 4 +- lib/Db/Currency.php | 10 +- lib/Db/CurrencyMapper.php | 4 +- lib/Db/Member.php | 52 ++--- lib/Db/MemberMapper.php | 29 ++- lib/Db/PaymentMode.php | 10 +- lib/Db/PaymentModeMapper.php | 4 +- lib/Db/Project.php | 30 +-- lib/Db/ProjectMapper.php | 6 +- lib/Db/Share.php | 30 +-- lib/Db/ShareMapper.php | 18 +- .../CloudFederationProviderCospend.php | 2 +- lib/Middleware/PublicAuthMiddleware.php | 4 +- .../Version030000Date20240921142937.php | 182 ++++++++++++++++++ .../Version030000Date20240921143001.php | 105 ++++++++++ lib/Search/CospendSearchProvider.php | 2 +- lib/Service/CospendService.php | 9 +- lib/Service/LocalProjectService.php | 144 +++++++------- lib/Service/UserService.php | 14 +- openapi-full.json | 50 ++++- openapi.json | 50 ++++- tests/php/service/LocalProjectServiceTest.php | 2 + 29 files changed, 611 insertions(+), 242 deletions(-) create mode 100644 lib/Migration/Version030000Date20240921142937.php create mode 100644 lib/Migration/Version030000Date20240921143001.php diff --git a/appinfo/info.xml b/appinfo/info.xml index 8e13dca95..4500aa152 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -3,7 +3,7 @@ cospend Cospend - 3.0.1 + 3.0.2 agpl Julien Veyssier Cospend diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 3b30db880..d3641667f 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -157,7 +157,8 @@ public function getLocalProjects(): DataResponse { /** * Get federated project list * - * @return DataResponse + * @return DataResponse, array{}> + * @throws Exception * * 200: Project list */ diff --git a/lib/Controller/PublicApiController.php b/lib/Controller/PublicApiController.php index 58f0c61a3..9a96e7a54 100644 --- a/lib/Controller/PublicApiController.php +++ b/lib/Controller/PublicApiController.php @@ -220,11 +220,11 @@ public function publicDeleteBills(string $token, array $billIds, bool $moveToTra #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT, tags: ['Public-API_Projects'])] public function publicGetProjectInfo(string $token): DataResponse { $share = $this->shareMapper->getLinkOrFederatedShareByToken($token); - $projectInfo = $this->localProjectService->getProjectInfo($share->getProjectid()); + $projectInfo = $this->localProjectService->getProjectInfo($share->getProjectId()); if ($projectInfo !== null) { unset($projectInfo['userid']); // set the visible access level for frontend - $projectInfo['myaccesslevel'] = $share->getAccesslevel() ; + $projectInfo['myaccesslevel'] = $share->getAccessLevel() ; return new DataResponse($projectInfo); } return new DataResponse( diff --git a/lib/Db/BillMapper.php b/lib/Db/BillMapper.php index f6cc9ee50..66b09e577 100644 --- a/lib/Db/BillMapper.php +++ b/lib/Db/BillMapper.php @@ -51,23 +51,6 @@ public function find(int $id): Bill { return $this->mapRowToEntity($row); } - /** - * Delete bill owers of given bill - * - * @param int $billId - * @return int - * @throws \OCP\DB\Exception - */ - public function deleteBillOwersOfBill(int $billId): int { - $qb = $this->db->getQueryBuilder(); - $qb->delete('cospend_bill_owers') - ->where( - $qb->expr()->eq('billid', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_INT)) - ); - $nbDeleted = $qb->executeStatement(); - return $nbDeleted; - } - public function deleteDeletedBills(string $projectId): void { // first delete the bill owers $qb = $this->db->getQueryBuilder(); @@ -84,7 +67,7 @@ public function deleteDeletedBills(string $projectId): void { $qb->delete('cospend_bill_owers') ->where( - $qb2->expr()->in('billid', $qb->createFunction($qb2->getSQL()), IQueryBuilder::PARAM_STR_ARRAY) + $qb2->expr()->in('bill_id', $qb->createFunction($qb2->getSQL()), IQueryBuilder::PARAM_STR_ARRAY) ); $qb->executeStatement(); @@ -130,7 +113,7 @@ public function deleteBills(string $projectId, ?string $what = null, ?int $minTi $qb->delete('cospend_bill_owers') ->where( - $qb2->expr()->in('billid', $qb->createFunction($qb2->getSQL()), IQueryBuilder::PARAM_STR_ARRAY) + $qb2->expr()->in('bill_id', $qb->createFunction($qb2->getSQL()), IQueryBuilder::PARAM_STR_ARRAY) ); $nbBillOwersDeleted = $qb->executeStatement(); $qb = $this->db->getQueryBuilder(); @@ -258,11 +241,11 @@ public function getBill(string $projectId, int $billId): ?array { $qb = $this->db->getQueryBuilder(); - $qb->select('memberid', 'm.name', 'm.weight', 'm.activated') + $qb->select('bo.member_id', 'm.name', 'm.weight', 'm.activated') ->from('cospend_bill_owers', 'bo') - ->innerJoin('bo', 'cospend_members', 'm', $qb->expr()->eq('bo.memberid', 'm.id')) + ->innerJoin('bo', 'cospend_members', 'm', $qb->expr()->eq('bo.member_id', 'm.id')) ->where( - $qb->expr()->eq('bo.billid', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_INT)) + $qb->expr()->eq('bo.bill_id', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_INT)) ); $req = $qb->executeQuery(); @@ -270,7 +253,7 @@ public function getBill(string $projectId, int $billId): ?array { $dbWeight = (float)$row['weight']; $dbName = $row['name']; $dbActivated = (((int)$row['activated']) === 1); - $dbOwerId = (int)$row['memberid']; + $dbOwerId = (int)$row['member_id']; $billOwers[] = [ 'id' => $dbOwerId, 'weight' => $dbWeight, @@ -342,10 +325,10 @@ public function getBillsClassic( $qb = $this->db->getQueryBuilder(); $qb->select('bi.id', 'what', 'comment', 'timestamp', 'amount', 'payer_id', 'repeat', 'payment_mode', 'payment_mode_id', 'category_id', 'bi.last_changed', 'repeat_all_active', 'repeat_until', 'repeat_frequency', - 'deleted', 'memberid', 'm.name', 'm.weight', 'm.activated') + 'deleted', 'bo.member_id', 'm.name', 'm.weight', 'm.activated') ->from('cospend_bill_owers', 'bo') - ->innerJoin('bo', 'cospend_bills', 'bi', $qb->expr()->eq('bo.billid', 'bi.id')) - ->innerJoin('bo', 'cospend_members', 'm', $qb->expr()->eq('bo.memberid', 'm.id')) + ->innerJoin('bo', 'cospend_bills', 'bi', $qb->expr()->eq('bo.bill_id', 'bi.id')) + ->innerJoin('bo', 'cospend_members', 'm', $qb->expr()->eq('bo.member_id', 'm.id')) ->where( $qb->expr()->eq('bi.project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)) ); @@ -432,7 +415,7 @@ public function getBillsClassic( $dbWeight = (float)$row['weight']; $dbName = $row['name']; $dbActivated = ((int)$row['activated']) === 1; - $dbOwerId = (int)$row['memberid']; + $dbOwerId = (int)$row['member_id']; $billDict[$dbBillId]['owers'][] = [ 'id' => $dbOwerId, 'weight' => $dbWeight, @@ -602,11 +585,11 @@ public function getBillsWithLimit( $billOwers = []; $billOwerIds = []; - $qb->select('memberid', 'm.name', 'm.weight', 'm.activated') + $qb->select('bo.member_id', 'm.name', 'm.weight', 'm.activated') ->from('cospend_bill_owers', 'bo') - ->innerJoin('bo', 'cospend_members', 'm', $qb->expr()->eq('bo.memberid', 'm.id')) + ->innerJoin('bo', 'cospend_members', 'm', $qb->expr()->eq('bo.member_id', 'm.id')) ->where( - $qb->expr()->eq('bo.billid', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_INT)) + $qb->expr()->eq('bo.bill_id', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_INT)) ); $qb->setFirstResult(0); $req = $qb->executeQuery(); @@ -614,7 +597,7 @@ public function getBillsWithLimit( $dbWeight = (float)$row['weight']; $dbName = $row['name']; $dbActivated = ((int)$row['activated']) === 1; - $dbOwerId = (int)$row['memberid']; + $dbOwerId = (int)$row['member_id']; $billOwers[] = [ 'id' => $dbOwerId, 'weight' => $dbWeight, @@ -711,7 +694,7 @@ public function searchBills(string $projectId, string $term, ?int $deleted = 0): $qb->select( 'b.id', 'what', 'comment', 'amount', 'timestamp', 'payment_mode', 'payment_mode_id', 'category_id', - 'pr.currency_name', 'me.name', 'me.userid' + 'pr.currency_name', 'me.name', 'me.user_id' ) ->from($this->getTableName(), 'b') ->innerJoin('b', 'cospend_projects', 'pr', $qb->expr()->eq('b.project_id', 'pr.id')) @@ -741,7 +724,7 @@ public function searchBills(string $projectId, string $term, ?int $deleted = 0): $dbCategoryId = (int)$row['category_id']; $dbProjectCurrencyName = $row['currency_name']; $dbPayerName = $row['name']; - $dbPayerUserId = $row['userid']; + $dbPayerUserId = $row['user_id']; $bills[] = [ 'id' => $dbBillId, 'projectId' => $projectId, diff --git a/lib/Db/BillOwer.php b/lib/Db/BillOwer.php index c5a04258d..c2ce2b64c 100644 --- a/lib/Db/BillOwer.php +++ b/lib/Db/BillOwer.php @@ -15,28 +15,28 @@ use OCP\AppFramework\Db\Entity; /** - * @method int getBillid() - * @method void setBillid(int $billid) - * @method int getMemberid() - * @method void setMemberid(int $memberid) + * @method int getBillId() + * @method void setBillId(int $billId) + * @method int getMemberId() + * @method void setMemberId(int $memberId) **/ class BillOwer extends Entity implements \JsonSerializable { - protected int $billid = 0; - protected int $memberid = 0; + protected int $billId = 0; + protected int $memberId = 0; public function __construct() { $this->addType('id', 'integer'); - $this->addType('billid', 'integer'); - $this->addType('memberid', 'integer'); + $this->addType('bill_id', 'integer'); + $this->addType('member_id', 'integer'); } #[\ReturnTypeWillChange] public function jsonSerialize() { return [ 'id' => $this->getId(), - 'billid' => $this->getBillid(), - 'memberid' => $this->getMemberid(), + 'billid' => $this->getBillId(), + 'memberid' => $this->getMemberId(), ]; } } diff --git a/lib/Db/BillOwerMapper.php b/lib/Db/BillOwerMapper.php index ed809aabb..7b0db4db9 100644 --- a/lib/Db/BillOwerMapper.php +++ b/lib/Db/BillOwerMapper.php @@ -54,7 +54,7 @@ public function deleteBillOwersOfBill(int $billId): int { $qb = $this->db->getQueryBuilder(); $qb->delete($this->getTableName()) ->where( - $qb->expr()->eq('billid', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_INT)) + $qb->expr()->eq('bill_id', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_INT)) ); $nbDeleted = $qb->executeStatement(); return $nbDeleted; @@ -70,7 +70,7 @@ public function getOwersOfBill(int $billId): array { $qb->select('*') ->from($this->getTableName()) - ->where($qb->expr()->eq('billid', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_STR))); + ->where($qb->expr()->eq('bill_id', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_STR))); return $this->findEntities($qb); } diff --git a/lib/Db/Category.php b/lib/Db/Category.php index 5cee48a1f..37f91b9aa 100644 --- a/lib/Db/Category.php +++ b/lib/Db/Category.php @@ -11,8 +11,8 @@ use OCP\AppFramework\Db\Entity; /** - * @method void setProjectid(string $projectid) - * @method string getProjectid() + * @method void setProjectId(string $projectId) + * @method string getProjectId() * @method void setName(string|null $name) * @method string|null getName() * @method void setColor(string|null $color) @@ -23,14 +23,14 @@ * @method int getOrder() */ class Category extends Entity implements \JsonSerializable { - protected string $projectid = ''; + protected string $projectId = ''; protected ?string $name = null; protected ?string $color = null; protected ?string $encodedIcon = null; protected int $order = 0; public function __construct() { - $this->addType('projectid', 'string'); + $this->addType('project_id', 'string'); $this->addType('name', 'string'); $this->addType('color', 'string'); $this->addType('encoded_icon', 'string'); @@ -40,7 +40,7 @@ public function __construct() { public function jsonSerialize(): array { return [ 'id' => $this->getId(), - 'projectid' => $this->getProjectid(), + 'projectid' => $this->getProjectId(), 'name' => $this->getName(), 'color' => $this->getColor(), 'icon' => $this->getEncodedIcon() === null ? null : urldecode($this->getEncodedIcon()), diff --git a/lib/Db/CategoryMapper.php b/lib/Db/CategoryMapper.php index 200c4e108..9d28b986f 100644 --- a/lib/Db/CategoryMapper.php +++ b/lib/Db/CategoryMapper.php @@ -61,7 +61,7 @@ public function getCategoryOfProject(string $projectId, int $id): Category { $qb->select('*') ->from($this->getTableName()) ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))) - ->andWhere($qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))); + ->andWhere($qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))); return $this->findEntity($qb); } @@ -76,7 +76,7 @@ public function getCategoriesOfProject(string $projectId): array { $qb->select('*') ->from($this->getTableName()) - ->where($qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))); + ->where($qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))); return $this->findEntities($qb); } diff --git a/lib/Db/Currency.php b/lib/Db/Currency.php index 80c8d06a3..52922c1a3 100644 --- a/lib/Db/Currency.php +++ b/lib/Db/Currency.php @@ -11,20 +11,20 @@ use OCP\AppFramework\Db\Entity; /** - * @method void setProjectid(string $projectid) - * @method string getProjectid() + * @method void setProjectId(string $projectId) + * @method string getProjectId() * @method void setName(string|null $name) * @method string|null getName() * @method void setExchangeRate(float|null $exchangeRate) * @method float|null getExchangeRate() */ class Currency extends Entity implements \JsonSerializable { - protected string $projectid = ''; + protected string $projectId = ''; protected ?string $name = null; protected ?float $exchangeRate = null; public function __construct() { - $this->addType('projectid', 'string'); + $this->addType('project_id', 'string'); $this->addType('name', 'string'); $this->addType('exchange_rate', 'float'); } @@ -32,7 +32,7 @@ public function __construct() { public function jsonSerialize(): array { return [ 'id' => $this->getId(), - 'projectid' => $this->getProjectid(), + 'projectid' => $this->getProjectId(), 'name' => $this->getName(), 'exchange_rate' => $this->getExchangeRate(), ]; diff --git a/lib/Db/CurrencyMapper.php b/lib/Db/CurrencyMapper.php index 52265132a..33b417053 100644 --- a/lib/Db/CurrencyMapper.php +++ b/lib/Db/CurrencyMapper.php @@ -61,7 +61,7 @@ public function getCurrencyOfProject(string $projectId, int $id): Currency { $qb->select('*') ->from($this->getTableName()) ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))) - ->andWhere($qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))); + ->andWhere($qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))); return $this->findEntity($qb); } @@ -76,7 +76,7 @@ public function getCurrenciesOfProject(string $projectId): array { $qb->select('*') ->from($this->getTableName()) - ->where($qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))); + ->where($qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))); return $this->findEntities($qb); } diff --git a/lib/Db/Member.php b/lib/Db/Member.php index f9c5bbc82..e10fa2a75 100644 --- a/lib/Db/Member.php +++ b/lib/Db/Member.php @@ -19,68 +19,68 @@ /** * @method int getId() * @method void setId(int $id) - * @method string getProjectid() - * @method void setProjectid(string $projectid) + * @method string getProjectId() + * @method void setProjectId(string $projectId) * @method string getName() * @method void setName(string $name) * @method float getWeight() * @method void setWeight(float $weight) * @method int getActivated() * @method void setActivated(int $activated) - * @method int getLastchanged() - * @method void setLastchanged(int $lastchanged) + * @method int getLastChanged() + * @method void setLastChanged(int $lastChanged) * @method string getColor() * @method void setColor(string $color) - * @method string|null getUserid() - * @method void setUserid(string|null $userid) + * @method string|null getUserId() + * @method void setUserId(string|null $userId) */ class Member extends Entity implements \JsonSerializable { - protected $projectid; - protected $name; - protected $weight; - protected $activated; - protected $lastchanged; - protected $color; - protected $userid; + protected string $projectId = ''; + protected string $name = ''; + protected float $weight = 0; + protected int $activated = 1; + protected int $lastChanged = 0; + protected ?string $color = null; + protected ?string $userId = null; private $avatarManager; public function __construct() { $this->addType('id', 'integer'); - $this->addType('projectid', 'string'); + $this->addType('project_id', 'string'); $this->addType('name', 'string'); $this->addType('weight', 'float'); $this->addType('activated', 'integer'); - $this->addType('lastchanged', 'integer'); + $this->addType('last_changed', 'integer'); $this->addType('color', 'string'); - $this->addType('userid', 'string'); + $this->addType('user_id', 'string'); $this->avatarManager = \OC::$server->get(IAvatarManager::class); } #[\ReturnTypeWillChange] public function jsonSerialize() { return [ - 'id' => $this->id, - 'name' => $this->name, - 'weight' => $this->weight, - 'activated' => $this->activated === 1, - 'lastchanged' => $this->lastchanged, - 'userid' => $this->userid, + 'id' => $this->getId(), + 'name' => $this->getName(), + 'weight' => $this->getWeight(), + 'activated' => $this->getActivated() === 1, + 'lastchanged' => $this->getLastChanged(), + 'userid' => $this->getUserId(), 'color' => $this->getColorArray(), ]; } private function getColorArray(): array { - if ($this->color === null) { - $av = $this->avatarManager->getGuestAvatar($this->name); - $avBgColor = $av->avatarBackgroundColor($this->name); + if ($this->getColor() === null) { + $av = $this->avatarManager->getGuestAvatar($this->getName()); + $avBgColor = $av->avatarBackgroundColor($this->getName()); return [ 'r' => $avBgColor->red(), 'g' => $avBgColor->green(), 'b' => $avBgColor->blue(), ]; } - return Utils::hexToRgb($this->color); + return Utils::hexToRgb($this->getColor()); } } diff --git a/lib/Db/MemberMapper.php b/lib/Db/MemberMapper.php index 233901cdb..95e06afcc 100644 --- a/lib/Db/MemberMapper.php +++ b/lib/Db/MemberMapper.php @@ -23,12 +23,11 @@ * @extends QBMapper */ class MemberMapper extends QBMapper { - public const TABLE_NAME = 'cospend_members'; public function __construct( IDBConnection $db, ) { - parent::__construct($db, self::TABLE_NAME, Member::class); + parent::__construct($db, 'cospend_members', Member::class); } /** @@ -39,9 +38,9 @@ public function __construct( public function getMemberByName(string $projectId, string $name): ?Member { $qb = $this->db->getQueryBuilder(); $qb->select('*') - ->from(self::TABLE_NAME) + ->from($this->getTableName()) ->where( - $qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)) + $qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)) ) ->andWhere( $qb->expr()->eq('name', $qb->createNamedParameter($name, IQueryBuilder::PARAM_STR)) @@ -62,12 +61,12 @@ public function getMemberByName(string $projectId, string $name): ?Member { public function getMemberByUserid(string $projectId, string $userId): ?Member { $qb = $this->db->getQueryBuilder(); $qb->select('*') - ->from(self::TABLE_NAME) + ->from($this->getTableName()) ->where( - $qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)) + $qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)) ) ->andWhere( - $qb->expr()->eq('userid', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) + $qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) ); try { @@ -85,9 +84,9 @@ public function getMemberByUserid(string $projectId, string $userId): ?Member { public function getMemberById(string $projectId, int $memberId): ?Member { $qb = $this->db->getQueryBuilder(); $qb->select('*') - ->from(self::TABLE_NAME) + ->from($this->getTableName()) ->where( - $qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)) + $qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)) ) ->andWhere( $qb->expr()->eq('id', $qb->createNamedParameter($memberId, IQueryBuilder::PARAM_INT)) @@ -119,13 +118,13 @@ public function getMembers(string $projectId, ?string $order = null, ?int $lastc } $qb->select('*') - ->from(self::TABLE_NAME) + ->from($this->getTableName()) ->where( - $qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)) + $qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)) ); if ($lastchanged !== null) { $qb->andWhere( - $qb->expr()->gt('lastchanged', $qb->createNamedParameter($lastchanged, IQueryBuilder::PARAM_INT)) + $qb->expr()->gt('last_changed', $qb->createNamedParameter($lastchanged, IQueryBuilder::PARAM_INT)) ); } $qb->orderBy($sqlOrder, 'ASC'); @@ -149,11 +148,11 @@ public function getBillIdsOfMember(int $memberId, ?int $deleted = 0): array { $qb = $this->db->getQueryBuilder(); $qb->select('bi.id') ->from('cospend_bill_owers', 'bo') - ->innerJoin('bo', 'cospend_bills', 'bi', $qb->expr()->eq('bo.billid', 'bi.id')) - ->innerJoin('bo', self::TABLE_NAME, 'm', $qb->expr()->eq('bo.memberid', 'm.id')); + ->innerJoin('bo', 'cospend_bills', 'bi', $qb->expr()->eq('bo.bill_id', 'bi.id')) + ->innerJoin('bo', $this->getTableName(), 'm', $qb->expr()->eq('bo.member_id', 'm.id')); $or = $qb->expr()->orx(); $or->add($qb->expr()->eq('bi.payer_id', $qb->createNamedParameter($memberId, IQueryBuilder::PARAM_INT))); - $or->add($qb->expr()->eq('bo.memberid', $qb->createNamedParameter($memberId, IQueryBuilder::PARAM_INT))); + $or->add($qb->expr()->eq('bo.member_id', $qb->createNamedParameter($memberId, IQueryBuilder::PARAM_INT))); $qb->where($or); if ($deleted !== null) { $qb->andWhere( diff --git a/lib/Db/PaymentMode.php b/lib/Db/PaymentMode.php index bd0ae36a0..778e18250 100644 --- a/lib/Db/PaymentMode.php +++ b/lib/Db/PaymentMode.php @@ -11,8 +11,8 @@ use OCP\AppFramework\Db\Entity; /** - * @method void setProjectid(string $projectid) - * @method string getProjectid() + * @method void setProjectId(string $projectId) + * @method string getProjectId() * @method void setName(string|null $name) * @method string|null getName() * @method void setColor(string|null $color) @@ -25,7 +25,7 @@ * @method string|null getOldId() */ class PaymentMode extends Entity implements \JsonSerializable { - protected string $projectid = ''; + protected string $projectId = ''; protected ?string $name = null; protected ?string $color = null; protected ?string $encodedIcon = null; @@ -33,7 +33,7 @@ class PaymentMode extends Entity implements \JsonSerializable { protected ?string $oldId = null; public function __construct() { - $this->addType('projectid', 'string'); + $this->addType('project_id', 'string'); $this->addType('name', 'string'); $this->addType('color', 'string'); $this->addType('encoded_icon', 'string'); @@ -44,7 +44,7 @@ public function __construct() { public function jsonSerialize(): array { return [ 'id' => $this->getId(), - 'projectid' => $this->getProjectid(), + 'projectid' => $this->getProjectId(), 'name' => $this->getName(), 'color' => $this->getColor(), 'icon' => $this->getEncodedIcon() === null ? null : urldecode($this->getEncodedIcon()), diff --git a/lib/Db/PaymentModeMapper.php b/lib/Db/PaymentModeMapper.php index cfde50268..c19f9fe58 100644 --- a/lib/Db/PaymentModeMapper.php +++ b/lib/Db/PaymentModeMapper.php @@ -61,7 +61,7 @@ public function getPaymentModeOfProject(string $projectId, int $id): PaymentMode $qb->select('*') ->from($this->getTableName()) ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))) - ->andWhere($qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))); + ->andWhere($qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))); return $this->findEntity($qb); } @@ -76,7 +76,7 @@ public function getPaymentModesOfProject(string $projectId): array { $qb->select('*') ->from($this->getTableName()) - ->where($qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))); + ->where($qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))); return $this->findEntities($qb); } diff --git a/lib/Db/Project.php b/lib/Db/Project.php index ac7d34f80..adc0e1448 100644 --- a/lib/Db/Project.php +++ b/lib/Db/Project.php @@ -31,14 +31,14 @@ * @method void setCategorySort(string $categorySort) * @method string getPaymentModeSort() * @method void setPaymentModeSort(string $paymentModeSort) - * @method string getCurrencyName() - * @method void setCurrencyName(string $currencyName) - * @method int getArchivedTs() - * @method void setArchivedTs(int $archivedTs) + * @method string|null getCurrencyName() + * @method void setCurrencyName(string|null $currencyName) + * @method int|null getArchivedTs() + * @method void setArchivedTs(int|null $archivedTs) */ class Project extends Entity implements \JsonSerializable { - protected ?string $userId = null; + protected string $userId = ''; protected string $name = ''; protected string $autoExport = 'n'; protected int $lastChanged = 0; @@ -64,17 +64,17 @@ public function __construct() { #[\ReturnTypeWillChange] public function jsonSerialize() { return [ - 'id' => $this->id, - 'userid' => $this->userId, - 'name' => $this->name, + 'id' => $this->getId(), + 'userid' => $this->getUserId(), + 'name' => $this->getName(), 'email' => '', - 'autoexport' => $this->autoExport, - 'lastchanged' => $this->lastChanged, - 'deletiondisabled' => $this->deletionDisabled === 1, - 'categorysort' => $this->categorySort, - 'paymentmodesort' => $this->paymentModeSort, - 'currencyname' => $this->currencyName, - 'archived_ts' => $this->archivedTs, + 'autoexport' => $this->getAutoExport(), + 'lastchanged' => $this->getLastChanged(), + 'deletiondisabled' => $this->getDeletionDisabled() === 1, + 'categorysort' => $this->getCategorySort(), + 'paymentmodesort' => $this->getPaymentModeSort(), + 'currencyname' => $this->getCurrencyName(), + 'archived_ts' => $this->getArchivedTs(), ]; } } diff --git a/lib/Db/ProjectMapper.php b/lib/Db/ProjectMapper.php index ff31685b6..aa98c531c 100644 --- a/lib/Db/ProjectMapper.php +++ b/lib/Db/ProjectMapper.php @@ -108,7 +108,7 @@ public function createProject( if ($createDefaultCategories) { foreach ($defaultCategories as $defaultCategory) { $category = new Category(); - $category->setProjectid($insertedProject->getId()); + $category->setProjectId($insertedProject->getId()); $category->setName($defaultCategory['name']); $category->setColor($defaultCategory['color']); $category->setEncodedIcon(urlencode($defaultCategory['icon'])); @@ -119,7 +119,7 @@ public function createProject( if ($createDefaultPaymentModes) { foreach ($defaultPaymentModes as $defaultPm) { $paymentMode = new PaymentMode(); - $paymentMode->setProjectid($insertedProject->getId()); + $paymentMode->setProjectId($insertedProject->getId()); $paymentMode->setName($defaultPm['name']); $paymentMode->setColor($defaultPm['color']); $paymentMode->setEncodedIcon(urlencode($defaultPm['icon'])); @@ -175,7 +175,7 @@ public function deleteBillOwersOfProject(string $projectId): void { $qb->delete('cospend_bill_owers') ->where( - $qb2->expr()->in('billid', $qb->createFunction($qb2->getSQL()), IQueryBuilder::PARAM_STR_ARRAY) + $qb2->expr()->in('bill_id', $qb->createFunction($qb2->getSQL()), IQueryBuilder::PARAM_STR_ARRAY) ); $qb->executeStatement(); } diff --git a/lib/Db/Share.php b/lib/Db/Share.php index 498ca1dc9..fdd520e5a 100644 --- a/lib/Db/Share.php +++ b/lib/Db/Share.php @@ -11,14 +11,14 @@ use OCP\AppFramework\Db\Entity; /** - * @method void setProjectid(string $projectid) - * @method string getProjectid() - * @method void setUserid(string|null $userid) - * @method string|null getUserid() + * @method void setProjectId(string $projectId) + * @method string getProjectId() + * @method void setUserId(string|null $userId) + * @method string|null getUserId() * @method void setType(string $type) * @method string getType() - * @method void setAccesslevel(int $accesslevel) - * @method int getAccesslevel() + * @method void setAccessLevel(int $accessLevel) + * @method int getAccessLevel() * @method void setManuallyAdded(int $manuallyAdded) * @method int getManuallyAdded() * @method void setLabel(string|null $label) @@ -37,10 +37,10 @@ class Share extends Entity implements \JsonSerializable { public const TYPE_GROUP = 'g'; public const TYPE_CIRCLE = 'c'; - protected string $projectid = ''; - protected ?string $userid = null; + protected string $projectId = ''; + protected ?string $userId = null; protected string $type = self::TYPE_USER; - protected int $accesslevel = 2; + protected int $accessLevel = 2; protected int $manuallyAdded = 1; protected ?string $label = null; protected ?string $password = null; @@ -48,10 +48,10 @@ class Share extends Entity implements \JsonSerializable { protected ?int $state = null; public function __construct() { - $this->addType('projectid', 'string'); - $this->addType('userid', 'string'); + $this->addType('project_id', 'string'); + $this->addType('user_id', 'string'); $this->addType('type', 'string'); - $this->addType('accesslevel', 'integer'); + $this->addType('access_level', 'integer'); $this->addType('manually_added', 'integer'); $this->addType('label', 'string'); $this->addType('password', 'string'); @@ -62,10 +62,10 @@ public function __construct() { public function jsonSerialize(): array { return [ 'id' => $this->getId(), - 'projectid' => $this->getProjectid(), - 'userid' => $this->getUserid(), + 'projectid' => $this->getProjectId(), + 'userid' => $this->getUserId(), 'type' => $this->getType(), - 'accesslevel' => $this->getAccesslevel(), + 'accesslevel' => $this->getAccessLevel(), 'manuallyAdded' => $this->getManuallyAdded() === 1, 'label' => $this->getLabel(), 'password' => $this->getPassword(), diff --git a/lib/Db/ShareMapper.php b/lib/Db/ShareMapper.php index adb73d419..91f43f171 100644 --- a/lib/Db/ShareMapper.php +++ b/lib/Db/ShareMapper.php @@ -63,7 +63,7 @@ public function getProjectShareById(string $projectId, int $id, ?string $type = $qb->select('*') ->from($this->getTableName()) ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))) - ->andWhere($qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))); + ->andWhere($qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))); if ($type !== null) { $qb->andWhere($qb->expr()->eq('type', $qb->createNamedParameter($type, IQueryBuilder::PARAM_STR))); @@ -87,7 +87,7 @@ public function getLinkShareByToken( $qb->select('*') ->from($this->getTableName()) - ->where($qb->expr()->eq('userid', $qb->createNamedParameter($token, IQueryBuilder::PARAM_STR))) + ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($token, IQueryBuilder::PARAM_STR))) ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(Share::TYPE_PUBLIC_LINK, IQueryBuilder::PARAM_STR))); return $this->findEntity($qb); @@ -108,7 +108,7 @@ public function getLinkOrFederatedShareByToken( $qb->select('*') ->from($this->getTableName()) - ->where($qb->expr()->eq('userid', $qb->createNamedParameter($token, IQueryBuilder::PARAM_STR))); + ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($token, IQueryBuilder::PARAM_STR))); $or = $qb->expr()->orx(); $or->add($qb->expr()->eq('type', $qb->createNamedParameter(Share::TYPE_FEDERATION, IQueryBuilder::PARAM_STR))); @@ -137,11 +137,11 @@ public function getFederatedShareByProjectIdAndUserCloudId( $qb->select('*') ->from($this->getTableName()) - ->where($qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))) + ->where($qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))) ->andWhere($qb->expr()->eq('user_cloud_id', $qb->createNamedParameter($userCloudId, IQueryBuilder::PARAM_STR))); if ($token !== null) { - $qb->andWhere($qb->expr()->eq('userid', $qb->createNamedParameter($token, IQueryBuilder::PARAM_STR))); + $qb->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($token, IQueryBuilder::PARAM_STR))); } return $this->findEntity($qb); @@ -157,7 +157,7 @@ public function getSharesForUser(string $userId): array { $qb->select('*') ->from($this->getTableName()) - ->where($qb->expr()->eq('userid', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))) + ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))) ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(Share::TYPE_USER, IQueryBuilder::PARAM_STR))); return $this->findEntities($qb); @@ -181,8 +181,8 @@ public function getShareByProjectAndUser( $qb->select('*') ->from($this->getTableName()) - ->where($qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))) - ->andWhere($qb->expr()->eq('userid', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))); + ->where($qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))) + ->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))); if ($type !== null) { $qb->andWhere($qb->expr()->eq('type', $qb->createNamedParameter($type, IQueryBuilder::PARAM_STR))); @@ -202,7 +202,7 @@ public function getSharesOfProject(string $projectId, ?string $type = null): arr $qb->select('*') ->from($this->getTableName()) - ->where($qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))); + ->where($qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))); if ($type !== null) { $qb->andWhere($qb->expr()->eq('type', $qb->createNamedParameter($type, IQueryBuilder::PARAM_STR))); diff --git a/lib/Federation/CloudFederationProviderCospend.php b/lib/Federation/CloudFederationProviderCospend.php index 8f008dec2..3d5511bbb 100644 --- a/lib/Federation/CloudFederationProviderCospend.php +++ b/lib/Federation/CloudFederationProviderCospend.php @@ -227,7 +227,7 @@ private function getLocalShareAndValidate( } catch (Exception) { throw new ShareNotFound(FederationManager::OCM_RESOURCE_NOT_FOUND); } - if ($share->getUserid() !== $sharedSecret) { + if ($share->getUserId() !== $sharedSecret) { throw new AuthenticationFailedException(); } return $share; diff --git a/lib/Middleware/PublicAuthMiddleware.php b/lib/Middleware/PublicAuthMiddleware.php index 1a0738a14..2b3dc941c 100644 --- a/lib/Middleware/PublicAuthMiddleware.php +++ b/lib/Middleware/PublicAuthMiddleware.php @@ -65,7 +65,7 @@ public function beforeController($controller, $methodName): void { /** @var CospendPublicAuth $cospendAuthAttr */ $cospendAuthAttr = $attribute->newInstance(); $minLevel = $cospendAuthAttr->getMinimumLevel(); - if ($share->getAccesslevel() < $minLevel) { + if ($share->getAccessLevel() < $minLevel) { throw new CospendPublicAuthNotValidException( $this->l->t('Insufficient access level'), Http::STATUS_UNAUTHORIZED, $paramToken, $paramPassword, 'insufficient permissions' @@ -73,7 +73,7 @@ public function beforeController($controller, $methodName): void { } } - $controller->projectId = $share->getProjectid(); + $controller->projectId = $share->getProjectId(); } } diff --git a/lib/Migration/Version030000Date20240921142937.php b/lib/Migration/Version030000Date20240921142937.php new file mode 100644 index 000000000..f6a2fca15 --- /dev/null +++ b/lib/Migration/Version030000Date20240921142937.php @@ -0,0 +1,182 @@ +hasTable('cospend_bill_owers')) { + $table = $schema->getTable('cospend_bill_owers'); + if (!$table->hasColumn('bill_id')) { + $table->addColumn('bill_id', Types::BIGINT, [ + 'notnull' => true, + 'unsigned' => true, + ]); + $schemaChanged = true; + } + if (!$table->hasColumn('member_id')) { + $table->addColumn('member_id', Types::BIGINT, [ + 'notnull' => true, + 'unsigned' => true, + ]); + $schemaChanged = true; + } + } + + if ($schema->hasTable('cospend_categories')) { + $table = $schema->getTable('cospend_categories'); + if (!$table->hasColumn('project_id')) { + $table->addColumn('project_id', Types::STRING, [ + 'notnull' => true, + 'length' => 64, + ]); + $schemaChanged = true; + } + } + + if ($schema->hasTable('cospend_currencies')) { + $table = $schema->getTable('cospend_currencies'); + if (!$table->hasColumn('project_id')) { + $table->addColumn('project_id', Types::STRING, [ + 'notnull' => true, + 'length' => 64, + ]); + $schemaChanged = true; + } + } + + if ($schema->hasTable('cospend_paymentmodes')) { + $table = $schema->getTable('cospend_paymentmodes'); + if (!$table->hasColumn('project_id')) { + $table->addColumn('project_id', Types::STRING, [ + 'notnull' => true, + 'length' => 64, + ]); + $schemaChanged = true; + } + } + + if ($schema->hasTable('cospend_shares')) { + $table = $schema->getTable('cospend_shares'); + if (!$table->hasColumn('project_id')) { + $table->addColumn('project_id', Types::STRING, [ + 'notnull' => true, + 'length' => 64, + ]); + $schemaChanged = true; + } + if (!$table->hasColumn('user_id')) { + $table->addColumn('user_id', Types::STRING, [ + 'notnull' => false, + 'length' => 64, + 'default' => null, + ]); + $schemaChanged = true; + } + if (!$table->hasColumn('access_level')) { + $table->addColumn('access_level', Types::INTEGER, [ + 'notnull' => true, + 'default' => Application::ACCESS_LEVEL_PARTICIPANT, + ]); + $schemaChanged = true; + } + } + + if ($schema->hasTable('cospend_members')) { + $table = $schema->getTable('cospend_members'); + if (!$table->hasColumn('project_id')) { + $table->addColumn('project_id', Types::STRING, [ + 'notnull' => true, + 'length' => 64, + ]); + $schemaChanged = true; + } + if (!$table->hasColumn('user_id')) { + $table->addColumn('user_id', Types::STRING, [ + 'notnull' => false, + 'length' => 64, + 'default' => null, + ]); + $schemaChanged = true; + } + if (!$table->hasColumn('last_changed')) { + $table->addColumn('last_changed', Types::BIGINT, [ + 'notnull' => true, + 'default' => 0, + 'unsigned' => true, + ]); + $schemaChanged = true; + } + } + + return $schemaChanged ? $schema : null; + } + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + */ + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { + $qb = $this->connection->getQueryBuilder(); + $qb->update('cospend_bill_owers'); + $qb->set('bill_id', 'billid'); + $qb->set('member_id', 'memberid'); + $qb->executeStatement(); + + $qb = $this->connection->getQueryBuilder(); + $qb->update('cospend_categories'); + $qb->set('project_id', 'projectid'); + $qb->executeStatement(); + + $qb = $this->connection->getQueryBuilder(); + $qb->update('cospend_currencies'); + $qb->set('project_id', 'projectid'); + $qb->executeStatement(); + + $qb = $this->connection->getQueryBuilder(); + $qb->update('cospend_paymentmodes'); + $qb->set('project_id', 'projectid'); + $qb->executeStatement(); + + $qb = $this->connection->getQueryBuilder(); + $qb->update('cospend_shares'); + $qb->set('project_id', 'projectid'); + $qb->set('user_id', 'userid'); + $qb->set('access_level', 'accesslevel'); + $qb->executeStatement(); + + $qb = $this->connection->getQueryBuilder(); + $qb->update('cospend_members'); + $qb->set('project_id', 'projectid'); + $qb->set('user_id', 'userid'); + $qb->set('last_changed', 'lastchanged'); + $qb->executeStatement(); + } +} diff --git a/lib/Migration/Version030000Date20240921143001.php b/lib/Migration/Version030000Date20240921143001.php new file mode 100644 index 000000000..020c9988f --- /dev/null +++ b/lib/Migration/Version030000Date20240921143001.php @@ -0,0 +1,105 @@ +hasTable('cospend_bill_owers')) { + $table = $schema->getTable('cospend_bill_owers'); + // drop columns that have been renamed + if ($table->hasColumn('bill_id') && $table->hasColumn('billid')) { + $table->dropColumn('billid'); + $schemaChanged = true; + } + if ($table->hasColumn('member_id') && $table->hasColumn('memberid')) { + $table->dropColumn('memberid'); + $schemaChanged = true; + } + } + + if ($schema->hasTable('cospend_categories')) { + $table = $schema->getTable('cospend_categories'); + // drop columns that have been renamed + if ($table->hasColumn('project_id') && $table->hasColumn('projectid')) { + $table->dropColumn('projectid'); + $schemaChanged = true; + } + } + + if ($schema->hasTable('cospend_currencies')) { + $table = $schema->getTable('cospend_currencies'); + // drop columns that have been renamed + if ($table->hasColumn('project_id') && $table->hasColumn('projectid')) { + $table->dropColumn('projectid'); + $schemaChanged = true; + } + } + + if ($schema->hasTable('cospend_paymentmodes')) { + $table = $schema->getTable('cospend_paymentmodes'); + // drop columns that have been renamed + if ($table->hasColumn('project_id') && $table->hasColumn('projectid')) { + $table->dropColumn('projectid'); + $schemaChanged = true; + } + } + + if ($schema->hasTable('cospend_shares')) { + $table = $schema->getTable('cospend_shares'); + // drop columns that have been renamed + if ($table->hasColumn('project_id') && $table->hasColumn('projectid')) { + $table->dropColumn('projectid'); + $schemaChanged = true; + } + if ($table->hasColumn('user_id') && $table->hasColumn('userid')) { + $table->dropColumn('userid'); + $schemaChanged = true; + } + if ($table->hasColumn('access_level') && $table->hasColumn('accesslevel')) { + $table->dropColumn('accesslevel'); + $schemaChanged = true; + } + } + + if ($schema->hasTable('cospend_members')) { + $table = $schema->getTable('cospend_members'); + // drop columns that have been renamed + if ($table->hasColumn('project_id') && $table->hasColumn('projectid')) { + $table->dropColumn('projectid'); + $schemaChanged = true; + } + if ($table->hasColumn('user_id') && $table->hasColumn('userid')) { + $table->dropColumn('userid'); + $schemaChanged = true; + } + if ($table->hasColumn('last_changed') && $table->hasColumn('lastchanged')) { + $table->dropColumn('lastchanged'); + $schemaChanged = true; + } + } + + return $schemaChanged ? $schema : null; + } +} diff --git a/lib/Search/CospendSearchProvider.php b/lib/Search/CospendSearchProvider.php index f2492c865..87338f7c6 100644 --- a/lib/Search/CospendSearchProvider.php +++ b/lib/Search/CospendSearchProvider.php @@ -115,7 +115,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult { $resultBills = array_slice($resultBills, $offset, $limit); // build formatted - $formattedResults = array_map(function (array $bill) use ($projectsById):SearchResultEntry { + $formattedResults = array_map(function (array $bill) use ($projectsById): SearchResultEntry { $projectId = $bill['projectId']; $thumbnailUrl = $this->getThumbnailUrl($bill); return new SearchResultEntry( diff --git a/lib/Service/CospendService.php b/lib/Service/CospendService.php index 368f16a8a..8bda08d1e 100644 --- a/lib/Service/CospendService.php +++ b/lib/Service/CospendService.php @@ -20,6 +20,7 @@ use OCA\Cospend\Db\InvitationMapper; use OCA\Cospend\Utils; +use OCP\DB\Exception; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\File; use OCP\Files\Folder; @@ -47,13 +48,19 @@ public function __construct( ) { } + /** + * @param string $userId + * @return list + * @throws Exception + */ public function getFederatedProjects(string $userId): array { $invitations = $this->invitationMapper->getInvitationsForUser($userId, Invitation::STATE_ACCEPTED); - return array_map(static function (Invitation $invitation) { + $jsonInvitations = array_map(static function (Invitation $invitation) { $jsonInvitation = $invitation->jsonSerialize(); unset($jsonInvitation['accessToken']); return $jsonInvitation; }, $invitations); + return array_values($jsonInvitations); } /** diff --git a/lib/Service/LocalProjectService.php b/lib/Service/LocalProjectService.php index 630041a33..9d1239843 100644 --- a/lib/Service/LocalProjectService.php +++ b/lib/Service/LocalProjectService.php @@ -206,8 +206,8 @@ public function getUserMaxAccessLevel(string $userId, string $projectId): int { // is the project shared with the user ? try { $userShare = $this->shareMapper->getShareByProjectAndUser($projectId, $userId, Share::TYPE_USER); - if ($userShare->getAccesslevel() > $userMaxAccessLevel) { - $userMaxAccessLevel = $userShare->getAccesslevel(); + if ($userShare->getAccessLevel() > $userMaxAccessLevel) { + $userMaxAccessLevel = $userShare->getAccessLevel(); } } catch (\Throwable $e) { } @@ -217,8 +217,8 @@ public function getUserMaxAccessLevel(string $userId, string $projectId): int { $groupShares = $this->shareMapper->getSharesOfProject($projectId, Share::TYPE_GROUP); foreach ($groupShares as $groupShare) { - $groupId = $groupShare->getUserid(); - $accessLevel = $groupShare->getAccesslevel(); + $groupId = $groupShare->getUserId(); + $accessLevel = $groupShare->getAccessLevel(); if ($this->groupManager->groupExists($groupId) && $this->groupManager->get($groupId)->inGroup($user) && $accessLevel > $userMaxAccessLevel @@ -232,8 +232,8 @@ public function getUserMaxAccessLevel(string $userId, string $projectId): int { if ($circlesEnabled) { $circleShares = $this->shareMapper->getSharesOfProject($projectId, Share::TYPE_CIRCLE); foreach ($circleShares as $circleShare) { - $circleId = $circleShare->getUserid(); - $accessLevel = $circleShare->getAccesslevel(); + $circleId = $circleShare->getUserId(); + $accessLevel = $circleShare->getAccessLevel(); if ($this->isUserInCircle($userId, $circleId) && $accessLevel > $userMaxAccessLevel) { $userMaxAccessLevel = $accessLevel; } @@ -257,7 +257,7 @@ public function getUserMaxAccessLevel(string $userId, string $projectId): int { */ public function getShareAccessLevel(string $projectId, int $shId): int { $share = $this->shareMapper->getProjectShareById($projectId, $shId); - return $share->getAccesslevel(); + return $share->getAccessLevel(); } /** @@ -293,28 +293,22 @@ public function deleteProject(string $projectId): void { $this->projectMapper->deleteBillOwersOfProject($projectId); $associatedTableNames = [ - // 'cospend_bills', - 'cospend_members', - 'cospend_shares', - 'cospend_currencies', - 'cospend_categories', - 'cospend_paymentmodes' + 'cospend_bills' => 'project_id', + 'cospend_members' => 'project_id', + 'cospend_shares' => 'project_id', + 'cospend_currencies' => 'project_id', + 'cospend_categories' => 'project_id', + 'cospend_paymentmodes' => 'project_id', ]; - $qb = $this->db->getQueryBuilder(); - foreach ($associatedTableNames as $tableName) { + foreach ($associatedTableNames as $tableName => $projectIdColumn) { + $qb = $this->db->getQueryBuilder(); $qb->delete($tableName) ->where( - $qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)) + $qb->expr()->eq($projectIdColumn, $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)) ); $qb->executeStatement(); - $qb = $this->db->getQueryBuilder(); } - $qb->delete('cospend_bills') - ->where( - $qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)) - ); - $qb->executeStatement(); $this->projectMapper->delete($dbProjectToDelete); } @@ -1005,8 +999,8 @@ public function createBill( // insert bill owers foreach ($owerIds as $owerId) { $billOwer = new BillOwer(); - $billOwer->setBillid($insertedBillId); - $billOwer->setMemberid((int)$owerId); + $billOwer->setBillId($insertedBillId); + $billOwer->setMemberId((int)$owerId); $this->billOwerMapper->insert($billOwer); } @@ -1376,7 +1370,7 @@ public function editMember( // UPDATE $ts = (new DateTime())->getTimestamp(); - $dbMember->setLastchanged($ts); + $dbMember->setLastChanged($ts); if ($weight !== null) { $dbMember->setWeight($weight); @@ -1394,7 +1388,7 @@ public function editMember( } if ($userId !== null) { - $dbMember->setUserid($userId === '' ? null : $userId); + $dbMember->setUserId($userId === '' ? null : $userId); } $this->memberMapper->update($dbMember); @@ -1505,10 +1499,10 @@ public function createMember( } $ts = (new DateTime())->getTimestamp(); - $newMember->setLastchanged($ts); - $newMember->setProjectid($projectId); + $newMember->setLastChanged($ts); + $newMember->setProjectId($projectId); if ($userId !== null) { - $newMember->setUserid($userId); + $newMember->setUserId($userId); } $newMember->setActivated($active ? 1 : 0); $newMember->setName($name); @@ -1645,9 +1639,9 @@ public function getProjectNames(?string $userId): array { // shared with user $qb->select('p.id', 'p.name') ->from('cospend_projects', 'p') - ->innerJoin('p', 'cospend_shares', 's', $qb->expr()->eq('p.id', 's.projectid')) + ->innerJoin('p', 'cospend_shares', 's', $qb->expr()->eq('p.id', 's.project_id')) ->where( - $qb->expr()->eq('s.userid', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) + $qb->expr()->eq('s.user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) ) ->andWhere( $qb->expr()->eq('s.type', $qb->createNamedParameter(Share::TYPE_USER, IQueryBuilder::PARAM_STR)) @@ -1669,15 +1663,15 @@ public function getProjectNames(?string $userId): array { // get group with which a project is shared $candidateGroupIds = []; - $qb->select('userid') + $qb->select('user_id') ->from('cospend_shares', 's') ->where( $qb->expr()->eq('type', $qb->createNamedParameter(Application::SHARE_TYPE_GROUP, IQueryBuilder::PARAM_STR)) ) - ->groupBy('userid'); + ->groupBy('user_id'); $req = $qb->executeQuery(); while ($row = $req->fetch()) { - $groupId = $row['userid']; + $groupId = $row['user_id']; $candidateGroupIds[] = $groupId; } $req->closeCursor(); @@ -1690,9 +1684,9 @@ public function getProjectNames(?string $userId): array { // get projects shared with this group $qb->select('p.id', 'p.name') ->from('cospend_projects', 'p') - ->innerJoin('p', 'cospend_shares', 's', $qb->expr()->eq('p.id', 's.projectid')) + ->innerJoin('p', 'cospend_shares', 's', $qb->expr()->eq('p.id', 's.project_id')) ->where( - $qb->expr()->eq('s.userid', $qb->createNamedParameter($candidateGroupId, IQueryBuilder::PARAM_STR)) + $qb->expr()->eq('s.user_id', $qb->createNamedParameter($candidateGroupId, IQueryBuilder::PARAM_STR)) ) ->andWhere( $qb->expr()->eq('s.type', $qb->createNamedParameter(Application::SHARE_TYPE_GROUP, IQueryBuilder::PARAM_STR)) @@ -1715,15 +1709,15 @@ public function getProjectNames(?string $userId): array { if ($circlesEnabled) { // get circles with which a project is shared $candidateCircleIds = []; - $qb->select('userid') + $qb->select('user_id') ->from('cospend_shares', 's') ->where( $qb->expr()->eq('type', $qb->createNamedParameter(Application::SHARE_TYPE_CIRCLE, IQueryBuilder::PARAM_STR)) ) - ->groupBy('userid'); + ->groupBy('user_id'); $req = $qb->executeQuery(); while ($row = $req->fetch()) { - $circleId = $row['userid']; + $circleId = $row['user_id']; $candidateCircleIds[] = $circleId; } $req->closeCursor(); @@ -1735,9 +1729,9 @@ public function getProjectNames(?string $userId): array { // get projects shared with this circle $qb->select('p.id', 'p.name') ->from('cospend_projects', 'p') - ->innerJoin('p', 'cospend_shares', 's', $qb->expr()->eq('p.id', 's.projectid')) + ->innerJoin('p', 'cospend_shares', 's', $qb->expr()->eq('p.id', 's.project_id')) ->where( - $qb->expr()->eq('s.userid', $qb->createNamedParameter($candidateCircleId, IQueryBuilder::PARAM_STR)) + $qb->expr()->eq('s.user_id', $qb->createNamedParameter($candidateCircleId, IQueryBuilder::PARAM_STR)) ) ->andWhere( $qb->expr()->eq('s.type', $qb->createNamedParameter(Application::SHARE_TYPE_CIRCLE, IQueryBuilder::PARAM_STR)) @@ -1834,7 +1828,7 @@ public function getCategoriesOrPaymentModes(string $projectId, bool $getCategori ->from($dbTable, $alias) ->innerJoin($alias, 'cospend_bills', 'bill', $qb->expr()->eq($alias . '.id', 'bill.' . $billTableField)) ->where( - $qb->expr()->eq($alias . '.projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)) + $qb->expr()->eq($alias . '.project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)) ) ->andWhere( $qb->expr()->eq('bill.deleted', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)) @@ -1860,7 +1854,7 @@ public function getCategoriesOrPaymentModes(string $projectId, bool $getCategori ->from($dbTable, $alias) ->innerJoin($alias, 'cospend_bills', 'bill', $qb->expr()->eq($alias . '.id', 'bill.' . $billTableField)) ->where( - $qb->expr()->eq($alias . '.projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)) + $qb->expr()->eq($alias . '.project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)) ) ->andWhere( $qb->expr()->eq('bill.deleted', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)) @@ -1926,10 +1920,10 @@ private function getUserShares(string $projectId): array { $shares = $this->shareMapper->getSharesOfProject($projectId, Share::TYPE_USER); foreach ($shares as $share) { - if (array_key_exists($share->getUserid(), $userIdToName)) { - $name = $userIdToName[$share->getUserid()]; + if (array_key_exists($share->getUserId(), $userIdToName)) { + $name = $userIdToName[$share->getUserId()]; } else { - $user = $this->userManager->get($share->getUserid()); + $user = $this->userManager->get($share->getUserId()); if ($user !== null) { $userIdToName[$user->getUID()] = $user->getDisplayName(); $name = $user->getDisplayName(); @@ -1991,7 +1985,7 @@ private function getGroupShares(string $projectId): array { $groupShares = $this->shareMapper->getSharesOfProject($projectId, Share::TYPE_GROUP); foreach ($groupShares as $groupShare) { - $groupId = $groupShare->getUserid(); + $groupId = $groupShare->getUserId(); if (array_key_exists($groupId, $groupIdToName)) { $name = $groupIdToName[$groupId]; } else { @@ -2005,7 +1999,7 @@ private function getGroupShares(string $projectId): array { } $jsonGroupShare = $groupShare->jsonSerialize(); $jsonGroupShare['name'] = $name; - $jsonGroupShare['groupid'] = $groupShare->getUserid(); + $jsonGroupShare['groupid'] = $groupShare->getUserId(); $jsonGroupShares[] = $jsonGroupShare; } @@ -2037,7 +2031,7 @@ private function getCircleShares(string $projectId): array { $circleShares = $this->shareMapper->getSharesOfProject($projectId, Share::TYPE_CIRCLE); foreach ($circleShares as $circleShare) { $jsonCircleShare = $circleShare->jsonSerialize(); - $circleId = $circleShare->getUserid(); + $circleId = $circleShare->getUserId(); $circle = $circlesManager->getCircle($circleId); $jsonCircleShare['name'] = $circle->getDisplayName(); $jsonCircleShare['circleid'] = $circleId; @@ -2253,8 +2247,8 @@ public function editBill( // insert bill owers foreach ($owerIds as $owerId) { $billOwer = new BillOwer(); - $billOwer->setBillid($billId); - $billOwer->setMemberid((int)$owerId); + $billOwer->setBillId($billId); + $billOwer->setMemberId((int)$owerId); $this->billOwerMapper->insert($billOwer); } } @@ -2713,7 +2707,7 @@ private function getNextRepetitionDate(array $bill, DateTimeImmutable $billDate) */ public function createPaymentMode(string $projectId, string $name, ?string $icon, string $color, ?int $order = 0): int { $pm = new PaymentMode(); - $pm->setProjectid($projectId); + $pm->setProjectId($projectId); $pm->setName($name); $pm->setOrder(is_null($order) ? 0 : $order); $pm->setColor($color); @@ -2810,7 +2804,7 @@ public function editPaymentMode( */ public function createCategory(string $projectId, string $name, ?string $icon, string $color, ?int $order = 0): int { $category = new Category(); - $category->setProjectid($projectId); + $category->setProjectId($projectId); $category->setName($name); $category->setOrder(is_null($order) ? 0 : $order); $category->setColor($color); @@ -2915,7 +2909,7 @@ public function createCurrency(string $projectId, string $name, float $rate): in $currency = new Currency(); $currency->setName($name); $currency->setExchangeRate($rate); - $currency->setProjectid($projectId); + $currency->setProjectId($projectId); $insertedCurrency = $this->currencyMapper->insert($currency); return $insertedCurrency->getId(); } @@ -3004,10 +2998,10 @@ public function createFederatedShare( ); $newShare = new Share(); - $newShare->setProjectid($projectId); - $newShare->setUserid($shareToken); + $newShare->setProjectId($projectId); + $newShare->setUserId($shareToken); $newShare->setType(Share::TYPE_FEDERATION); - $newShare->setAccesslevel($accessLevel); + $newShare->setAccessLevel($accessLevel); $newShare->setUserCloudId($userCloudId); $newShare->setState(Invitation::STATE_PENDING); $insertedShare = $this->shareMapper->insert($newShare); @@ -3040,7 +3034,7 @@ public function deleteFederatedShare(string $projectId, int $shId): void { throw new CospendBasicException('Share does not exist', Http::STATUS_BAD_REQUEST); } - if ($share->getProjectid() !== $projectId) { + if ($share->getProjectId() !== $projectId) { throw new CospendBasicException('Wrong projectId in the share to delete', Http::STATUS_BAD_REQUEST); } @@ -3049,7 +3043,7 @@ public function deleteFederatedShare(string $projectId, int $shId): void { $this->backendNotifier->sendRemoteUnShare( $cloudId->getRemote(), $projectId, - $share->getUserid(), + $share->getUserId(), ); $this->shareMapper->delete($share); @@ -3096,10 +3090,10 @@ public function createUserShare( } $share = new Share(); - $share->setProjectid($projectId); - $share->setUserid($userId); + $share->setProjectId($projectId); + $share->setUserId($userId); $share->setType(Share::TYPE_USER); - $share->setAccesslevel($accesslevel); + $share->setAccessLevel($accesslevel); $share->setManuallyAdded($manually_added ? 1 : 0); $insertedShare = $this->shareMapper->insert($share); @@ -3156,10 +3150,10 @@ public function createPublicShare( ISecureRandom::CHAR_HUMAN_READABLE ); $share = new Share(); - $share->setProjectid($projectId); - $share->setUserid($shareToken); + $share->setProjectId($projectId); + $share->setUserId($shareToken); $share->setType(Share::TYPE_PUBLIC_LINK); - $share->setAccesslevel($accesslevel); + $share->setAccessLevel($accesslevel); $share->setLabel($label); $share->setPassword($password); $insertedShare = $this->shareMapper->insert($share); @@ -3212,7 +3206,7 @@ public function createPublicShare( public function editShareAccessLevel(string $projectId, int $shId, int $accessLevel): array { try { $share = $this->shareMapper->getProjectShareById($projectId, $shId); - $share->setAccesslevel($accessLevel); + $share->setAccessLevel($accessLevel); $this->shareMapper->update($share); return ['success' => true]; } catch (DoesNotExistException $e) { @@ -3268,7 +3262,7 @@ public function deleteUserShare(string $projectId, int $shId, ?string $fromUserI } catch (DoesNotExistException $e) { return ['message' => $this->l10n->t('No such share')]; } - $dbUserId = $share->getUserid(); + $dbUserId = $share->getUserId(); $this->shareMapper->delete($share); // activity @@ -3387,10 +3381,10 @@ public function createGroupShare( } $share = new Share(); - $share->setProjectid($projectId); - $share->setUserid($groupId); + $share->setProjectId($projectId); + $share->setUserId($groupId); $share->setType(Share::TYPE_GROUP); - $share->setAccesslevel($accessLevel); + $share->setAccessLevel($accessLevel); $insertedShare = $this->shareMapper->insert($share); // activity @@ -3420,7 +3414,7 @@ public function deleteGroupShare(string $projectId, int $shId, ?string $fromUser } catch (DoesNotExistException $e) { return ['message' => $this->l10n->t('No such share')]; } - $dbGroupId = $share->getUserid(); + $dbGroupId = $share->getUserId(); $this->shareMapper->delete($share); // activity $projectObj = $this->projectMapper->find($projectId); @@ -3476,10 +3470,10 @@ public function createCircleShare( } $share = new Share(); - $share->setProjectid($projectId); - $share->setUserid($circleId); + $share->setProjectId($projectId); + $share->setUserId($circleId); $share->setType(Share::TYPE_CIRCLE); - $share->setAccesslevel($accesslevel); + $share->setAccessLevel($accesslevel); $insertedShare = $this->shareMapper->insert($share); // activity @@ -3509,7 +3503,7 @@ public function createCircleShare( public function deleteCircleShare(string $projectId, int $shId, ?string $fromUserId = null): array { try { $share = $this->shareMapper->getProjectShareById($projectId, $shId, Share::TYPE_CIRCLE); - $dbCircleId = $share->getUserid(); + $dbCircleId = $share->getUserId(); $this->shareMapper->delete($share); // activity diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 7bd4a00c5..b19bee1e0 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -36,37 +36,37 @@ public function findUsers($projectid): array { // get user shares from project id $qb = $this->dbconnection->getQueryBuilder(); - $qb->select('userid') + $qb->select('user_id') ->from('cospend_shares', 's') ->where( $qb->expr()->eq('type', $qb->createNamedParameter(Application::SHARE_TYPE_USER, IQueryBuilder::PARAM_STR)) ) ->andWhere( - $qb->expr()->eq('projectid', $qb->createNamedParameter($projectid, IQueryBuilder::PARAM_STR)) + $qb->expr()->eq('project_id', $qb->createNamedParameter($projectid, IQueryBuilder::PARAM_STR)) ); $req = $qb->executeQuery(); while ($row = $req->fetch()) { - if (!in_array($row['userid'], $userIds)) { - array_push($userIds, $row['userid']); + if (!in_array($row['user_id'], $userIds)) { + $userIds[] = $row['user_id']; } } $req->closeCursor(); $qb = $this->dbconnection->getQueryBuilder(); // get group shares from project id - $qb->select('userid') + $qb->select('user_id') ->from('cospend_shares', 's') ->where( $qb->expr()->eq('type', $qb->createNamedParameter(Application::SHARE_TYPE_GROUP, IQueryBuilder::PARAM_STR)) ) ->andWhere( - $qb->expr()->eq('projectid', $qb->createNamedParameter($projectid, IQueryBuilder::PARAM_STR)) + $qb->expr()->eq('project_id', $qb->createNamedParameter($projectid, IQueryBuilder::PARAM_STR)) ); $req = $qb->executeQuery(); /** @var string[] $groupIds */ $groupIds = []; while ($row = $req->fetch()) { - $groupIds[] = (string)$row['userid']; + $groupIds[] = (string)$row['user_id']; } $req->closeCursor(); // get users of groups diff --git a/openapi-full.json b/openapi-full.json index cb8bb2f53..7baa01880 100644 --- a/openapi-full.json +++ b/openapi-full.json @@ -1238,7 +1238,45 @@ "data": { "type": "array", "items": { - "$ref": "#/components/schemas/FullProjectInfo" + "type": "object", + "required": [ + "id", + "remoteProjectId", + "remoteProjectName", + "remoteServerUrl", + "state", + "userId", + "inviterCloudId", + "inviterDisplayName" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "remoteProjectId": { + "type": "string" + }, + "remoteProjectName": { + "type": "string" + }, + "remoteServerUrl": { + "type": "string" + }, + "state": { + "type": "integer", + "format": "int64" + }, + "userId": { + "type": "string" + }, + "inviterCloudId": { + "type": "string" + }, + "inviterDisplayName": { + "type": "string" + } + } } } } @@ -1247,6 +1285,16 @@ } } } + }, + "500": { + "description": "", + "content": { + "text/plain": { + "schema": { + "type": "string" + } + } + } } } } diff --git a/openapi.json b/openapi.json index 4ad5c4d3a..e1f271cc2 100644 --- a/openapi.json +++ b/openapi.json @@ -1188,7 +1188,45 @@ "data": { "type": "array", "items": { - "$ref": "#/components/schemas/FullProjectInfo" + "type": "object", + "required": [ + "id", + "remoteProjectId", + "remoteProjectName", + "remoteServerUrl", + "state", + "userId", + "inviterCloudId", + "inviterDisplayName" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "remoteProjectId": { + "type": "string" + }, + "remoteProjectName": { + "type": "string" + }, + "remoteServerUrl": { + "type": "string" + }, + "state": { + "type": "integer", + "format": "int64" + }, + "userId": { + "type": "string" + }, + "inviterCloudId": { + "type": "string" + }, + "inviterDisplayName": { + "type": "string" + } + } } } } @@ -1197,6 +1235,16 @@ } } } + }, + "500": { + "description": "", + "content": { + "text/plain": { + "schema": { + "type": "string" + } + } + } } } } diff --git a/tests/php/service/LocalProjectServiceTest.php b/tests/php/service/LocalProjectServiceTest.php index fe61e1fc8..2a312d6bf 100644 --- a/tests/php/service/LocalProjectServiceTest.php +++ b/tests/php/service/LocalProjectServiceTest.php @@ -140,6 +140,8 @@ private function deleteTestProjects(): void { 'newproject', 'superprojS', 'tsl', + 'tdm', + 'testGetSettlement', ]; foreach ($projIds as $projId) { try {