Fix primary key usage with different types

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-03-29 13:17:24 +02:00
parent 17c63989b1
commit 541fc9cfbb
10 changed files with 30 additions and 27 deletions

View File

@@ -24,13 +24,15 @@
namespace OCA\Deck\Db; namespace OCA\Deck\Db;
use OCP\Share\IShare;
class Circle extends RelationalObject { class Circle extends RelationalObject {
/** @var \OCA\Circles\Model\Circle */ /** @var \OCA\Circles\Model\Circle */
protected $object; protected $object;
public function __construct(\OCA\Circles\Model\Circle $circle) { public function __construct(\OCA\Circles\Model\Circle $circle) {
$primaryKey = $circle->getUniqueId(); $primaryKey = IShare::TYPE_CIRCLE . ':' . $circle->getUniqueId();
parent::__construct($primaryKey, $circle); parent::__construct($primaryKey, $circle);
} }
@@ -42,4 +44,4 @@ class Circle extends RelationalObject {
'circleOwner' => $this->object->getOwner() 'circleOwner' => $this->object->getOwner()
]; ];
} }
} }

View File

@@ -24,11 +24,12 @@
namespace OCA\Deck\Db; namespace OCA\Deck\Db;
use OCP\IGroup; use OCP\IGroup;
use OCP\Share\IShare;
class Group extends RelationalObject { class Group extends RelationalObject {
public function __construct(IGroup $group) { public function __construct(IGroup $group) {
$primaryKey = $group->getGID(); $primaryKey = IShare::TYPE_GROUP . ':' . $group->getGID();
parent::__construct($primaryKey, $group); parent::__construct($primaryKey, $group);
} }
@@ -38,4 +39,4 @@ class Group extends RelationalObject {
'displayname' => $this->object->getDisplayName() 'displayname' => $this->object->getDisplayName()
]; ];
} }
} }

View File

@@ -24,11 +24,12 @@
namespace OCA\Deck\Db; namespace OCA\Deck\Db;
use OCP\IUser; use OCP\IUser;
use OCP\Share\IShare;
class User extends RelationalObject { class User extends RelationalObject {
public function __construct(IUser $user) { public function __construct(IUser $user) {
$primaryKey = $user->getUID(); $primaryKey = IShare::TYPE_USER . ':' . $user->getUID();
parent::__construct($primaryKey, $user); parent::__construct($primaryKey, $user);
} }
@@ -46,4 +47,4 @@ class User extends RelationalObject {
public function getDisplayName() { public function getDisplayName() {
return $this->object->getDisplayName(); return $this->object->getDisplayName();
} }
} }

View File

@@ -126,7 +126,7 @@ class AssignmentService {
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT); $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
$assignments = $this->assignedUsersMapper->find($cardId); $assignments = $this->assignedUsersMapper->find($cardId);
foreach ($assignments as $assignment) { foreach ($assignments as $assignment) {
if ($assignment->getParticipant() === $userId) { if ($assignment->getParticipant() === $userId && $assignment->getType() === $type) {
throw new BadRequestException('The user is already assigned to the card'); throw new BadRequestException('The user is already assigned to the card');
} }
} }

View File

@@ -23,7 +23,7 @@
</span> </span>
</span> </span>
</li> </li>
<li v-for="acl in board.acl" :key="acl.participant.uid"> <li v-for="acl in board.acl" :key="acl.participant.primaryKey">
<Avatar v-if="acl.type===0" :user="acl.participant.uid" /> <Avatar v-if="acl.type===0" :user="acl.participant.uid" />
<div v-if="acl.type===1" class="avatardiv icon icon-group" /> <div v-if="acl.type===1" class="avatardiv icon icon-group" />
<div v-if="acl.type===7" class="avatardiv icon icon-circles" /> <div v-if="acl.type===7" class="avatardiv icon icon-circles" />
@@ -33,10 +33,10 @@
<span v-if="acl.type===7">{{ t('deck', '(Circle)') }}</span> <span v-if="acl.type===7">{{ t('deck', '(Circle)') }}</span>
</span> </span>
<ActionCheckbox v-if="!isCurrentUser(acl.participant.uid) && (canManage || (canEdit && canShare))" :checked="acl.permissionEdit" @change="clickEditAcl(acl)"> <ActionCheckbox v-if="!(isCurrentUser(acl.participant.uid) && acl.type === 0) && (canManage || (canEdit && canShare))" :checked="acl.permissionEdit" @change="clickEditAcl(acl)">
{{ t('deck', 'Can edit') }} {{ t('deck', 'Can edit') }}
</ActionCheckbox> </ActionCheckbox>
<Actions v-if="!isCurrentUser(acl.participant.uid)" :force-menu="true"> <Actions v-if="!(isCurrentUser(acl.participant.uid) && acl.type === 0)" :force-menu="true">
<ActionCheckbox v-if="canManage || canShare" :checked="acl.permissionShare" @change="clickShareAcl(acl)"> <ActionCheckbox v-if="canManage || canShare" :checked="acl.permissionShare" @change="clickShareAcl(acl)">
{{ t('deck', 'Can share') }} {{ t('deck', 'Can share') }}
</ActionCheckbox> </ActionCheckbox>

View File

@@ -61,10 +61,9 @@
<div class="section-wrapper"> <div class="section-wrapper">
<div v-tooltip="t('deck', 'Assign to users')" class="section-label icon-group"> <div v-tooltip="t('deck', 'Assign to users')" class="section-label icon-group">
<span class="hidden-visually">{{ t('deck', 'Assign to users') }}</span> <span class="hidden-visually">{{ t('deck', 'Assign to users/groups/circles') }}</span>
</div> </div>
<div class="section-details"> <div class="section-details">
<!-- FIXME: model not wokring due to id -->
<Multiselect v-if="canEdit" <Multiselect v-if="canEdit"
v-model="assignedUsers" v-model="assignedUsers"
:multiple="true" :multiple="true"
@@ -78,7 +77,7 @@
@remove="removeUserFromCard"> @remove="removeUserFromCard">
<template #tag="scope"> <template #tag="scope">
<div class="avatarlist--inline"> <div class="avatarlist--inline">
<Avatar :user="scope.option.primaryKey" <Avatar :user="scope.option.uid"
:display-name="scope.option.displayname" :display-name="scope.option.displayname"
:size="24" :size="24"
:disable-menu="true" /> :disable-menu="true" />
@@ -87,8 +86,8 @@
</Multiselect> </Multiselect>
<div v-else class="avatar-list--readonly"> <div v-else class="avatar-list--readonly">
<Avatar v-for="option in currentCard.assignedUsers" <Avatar v-for="option in currentCard.assignedUsers"
:key="option.id" :key="option.primaryKey"
:user="option.participant.primaryKey" :user="option.participant.uid"
:display-name="option.participant.displayname" :display-name="option.participant.displayname"
:size="32" /> :size="32" />
</div> </div>

View File

@@ -26,7 +26,7 @@
<At ref="at" <At ref="at"
v-model="commentText" v-model="commentText"
:members="members" :members="members"
name-key="primaryKey" name-key="uid"
:tab-select="true"> :tab-select="true">
<template v-slot:item="s"> <template v-slot:item="s">
<Avatar class="atwho-li--avatar" :user="s.item.uid" :size="24" /> <Avatar class="atwho-li--avatar" :user="s.item.uid" :size="24" />
@@ -34,9 +34,9 @@
</template> </template>
<template v-slot:embeddedItem="scope"> <template v-slot:embeddedItem="scope">
<span> <span>
<UserBubble v-if="scope.current.primaryKey" <UserBubble v-if="scope.current.uid"
:data-mention-id="scope.current.primaryKey" :data-mention-id="scope.current.uid"
:user="scope.current.primaryKey" :user="scope.current.uid"
:display-name="scope.current.displayname" /> :display-name="scope.current.displayname" />
</span> </span>
</template> </template>

View File

@@ -34,15 +34,15 @@
:size="32" /> :size="32" />
<Avatar v-if="user.type === 1" <Avatar v-if="user.type === 1"
:user="user.participant.primaryKey" :user="user.participant.primaryKey"
:display-name="user.participant.primaryKey" :display-name="user.participant.displayname"
:tooltip-message="user.participant.primaryKey + ' ' + t('deck', '(group)')" :tooltip-message="user.participant.displayname + ' ' + t('deck', '(group)')"
:is-no-user="true" :is-no-user="true"
:disable-="true" :disable-="true"
:size="32" /> :size="32" />
<Avatar v-if="user.type === 7" <Avatar v-if="user.type === 7"
:user="user.participant.primaryKey" :user="user.participant.primaryKey"
:display-name="user.participant.primaryKey" :display-name="user.participant.displayname"
:tooltip-message="user.participant.primaryKey + ' ' + t('deck', '(circle)')" :tooltip-message="user.participant.displayname + ' ' + t('deck', '(circle)')"
:is-no-user="true" :is-no-user="true"
:disable-="true" :disable-="true"
:size="32" /> :size="32" />
@@ -91,7 +91,7 @@ export default {
if (assignable.type === 1) { if (assignable.type === 1) {
return 'icon-group' return 'icon-group'
} }
const user = assignable.participant.primaryKey const user = assignable.participant.uid
const size = 32 const size = 32
const avatarUrl = OC.generateUrl('/avatar/{user}/{size}', const avatarUrl = OC.generateUrl('/avatar/{user}/{size}',
{ {

View File

@@ -57,7 +57,7 @@ class GroupTest extends \Test\TestCase {
$expected = [ $expected = [
'uid' => 'mygroup', 'uid' => 'mygroup',
'displayname' => 'My Group', 'displayname' => 'My Group',
'primaryKey' => 'mygroup' 'primaryKey' => '1:mygroup'
]; ];
$actual = $groupRelationalObject->jsonSerialize(); $actual = $groupRelationalObject->jsonSerialize();

View File

@@ -57,8 +57,8 @@ class UserTest extends \Test\TestCase {
$expected = [ $expected = [
'uid' => 'myuser', 'uid' => 'myuser',
'displayname' => 'myuser displayname', 'displayname' => 'myuser displayname',
'primaryKey' => 'myuser' 'primaryKey' => '0:myuser'
]; ];
$this->assertEquals($expected, $userRelationalObject->jsonSerialize()); $this->assertEquals($expected, $userRelationalObject->jsonSerialize());
} }
} }