parent
77c8083101
commit
318bf3ce3b
@ -1,62 +0,0 @@ |
||||
<template> |
||||
<div> |
||||
<Toolbar |
||||
:handle-submit="onSendFormData" |
||||
:handle-reset="resetForm" |
||||
/> |
||||
<DocumentsForm |
||||
ref="createForm" |
||||
:values="item" |
||||
:errors="violations" |
||||
/> |
||||
<Loading :visible="isLoading" /> |
||||
</div> |
||||
</template> |
||||
|
||||
<script> |
||||
import { mapActions } from 'vuex'; |
||||
import { createHelpers } from 'vuex-map-fields'; |
||||
import DocumentsForm from '../../components/personalfile/Form.vue'; |
||||
import Loading from '../../components/Loading.vue'; |
||||
import Toolbar from '../../components/Toolbar.vue'; |
||||
import CreateMixin from '../../mixins/CreateMixin'; |
||||
|
||||
const servicePrefix = 'PersonalFile'; |
||||
|
||||
const { mapFields } = createHelpers({ |
||||
getterType: 'personalfile/getField', |
||||
mutationType: 'personalfile/updateField' |
||||
}); |
||||
|
||||
export default { |
||||
name: 'PersonalFileCreate', |
||||
servicePrefix, |
||||
components: { |
||||
Loading, |
||||
Toolbar, |
||||
DocumentsForm |
||||
}, |
||||
mixins: [CreateMixin], |
||||
data() { |
||||
return { |
||||
item: {}, |
||||
type: 'folder' |
||||
}; |
||||
}, |
||||
computed: { |
||||
...mapFields(['error', 'isLoading', 'created', 'violations']) |
||||
}, |
||||
created() { |
||||
this.item.parentResourceNodeId = this.$route.params.node; |
||||
this.item.resourceLinkList = JSON.stringify([{ |
||||
gid: this.$route.query.gid, |
||||
sid: this.$route.query.sid, |
||||
cid: this.$route.query.cid, |
||||
visibility: 2, // visible by default |
||||
}]); |
||||
}, |
||||
methods: { |
||||
...mapActions('personalfile', ['createWithFormData', 'reset']) |
||||
} |
||||
}; |
||||
</script> |
||||
@ -0,0 +1,53 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Entity\Listener; |
||||
|
||||
use Chamilo\CoreBundle\Entity\ResourceNode; |
||||
use Chamilo\CoreBundle\Entity\User; |
||||
use Chamilo\CoreBundle\Entity\UserRelUser; |
||||
use Chamilo\CoreBundle\Repository\Node\UserRepository; |
||||
use Doctrine\ORM\Event\LifecycleEventArgs; |
||||
use Symfony\Component\Security\Core\Exception\UserNotFoundException; |
||||
use Symfony\Component\Security\Core\Security; |
||||
|
||||
class UserRelUserListener |
||||
{ |
||||
private Security $security; |
||||
|
||||
public function __construct(Security $security) |
||||
{ |
||||
$this->security = $security; |
||||
} |
||||
|
||||
public function prePersist(UserRelUser $userRelUser, LifecycleEventArgs $args): void |
||||
{ |
||||
$currentUser = $this->security->getUser(); |
||||
// User cannot be connected to himself |
||||
if ($userRelUser->getFriend()->getUsername() === $currentUser->getUserIdentifier()) { |
||||
throw new \Exception('Invalid relation UserRelUser'); |
||||
} |
||||
} |
||||
|
||||
public function postRemove(UserRelUser $userRelUser, LifecycleEventArgs $args) |
||||
{ |
||||
// Deletes the other connection |
||||
$em = $args->getEntityManager(); |
||||
$repo = $em->getRepository(UserRelUser::class); |
||||
$connection = $repo->findOneBy( |
||||
[ |
||||
'user' => $userRelUser->getFriend(), |
||||
'friend' => $userRelUser->getUser(), |
||||
'relationType' => $userRelUser->getRelationType(), |
||||
] |
||||
); |
||||
|
||||
if (null !== $connection) { |
||||
$em->remove($connection); |
||||
$em->flush(); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue