added team permissions for activities (#1872)
This commit is contained in:
@@ -14,6 +14,7 @@ use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
use Swagger\Annotations as SWG;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
@@ -42,7 +43,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
* options={
|
||||
* @Serializer\SerializedName("project"),
|
||||
* @Serializer\Type(name="integer"),
|
||||
* @Serializer\Groups({"Default"})
|
||||
* @Serializer\Groups({"Activity", "Team", "Not_Expanded"})
|
||||
* }
|
||||
* )
|
||||
*
|
||||
@@ -70,6 +71,10 @@ class Activity implements EntityWithMetaFields
|
||||
/**
|
||||
* @var Project|null
|
||||
*
|
||||
* @Serializer\Expose()
|
||||
* @Serializer\Groups({"Subresource", "Expanded"})
|
||||
* @SWG\Property(ref="#/definitions/Project")
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Project")
|
||||
* @ORM\JoinColumn(onDelete="CASCADE")
|
||||
*/
|
||||
@@ -164,10 +169,34 @@ class Activity implements EntityWithMetaFields
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\ActivityMeta", mappedBy="activity", cascade={"persist"})
|
||||
*/
|
||||
private $meta;
|
||||
/**
|
||||
* Teams
|
||||
*
|
||||
* If no team is assigned, everyone can access the activity
|
||||
*
|
||||
* @var Team[]|ArrayCollection
|
||||
*
|
||||
* @Serializer\Expose()
|
||||
* @Serializer\Groups({"Activity"})
|
||||
* @SWG\Property(type="array", @SWG\Items(ref="#/definitions/Team"))
|
||||
*
|
||||
* @ORM\ManyToMany(targetEntity="Team", cascade={"persist"}, inversedBy="activities")
|
||||
* @ORM\JoinTable(
|
||||
* name="kimai2_activities_teams",
|
||||
* joinColumns={
|
||||
* @ORM\JoinColumn(name="activity_id", referencedColumnName="id", onDelete="CASCADE")
|
||||
* },
|
||||
* inverseJoinColumns={
|
||||
* @ORM\JoinColumn(name="team_id", referencedColumnName="id", onDelete="CASCADE")
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
private $teams;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->meta = new ArrayCollection();
|
||||
$this->teams = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
@@ -300,6 +329,33 @@ class Activity implements EntityWithMetaFields
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addTeam(Team $team)
|
||||
{
|
||||
if ($this->teams->contains($team)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->teams->add($team);
|
||||
$team->addActivity($this);
|
||||
}
|
||||
|
||||
public function removeTeam(Team $team)
|
||||
{
|
||||
if (!$this->teams->contains($team)) {
|
||||
return;
|
||||
}
|
||||
$this->teams->removeElement($team);
|
||||
$team->removeActivity($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<Team>
|
||||
*/
|
||||
public function getTeams(): Collection
|
||||
{
|
||||
return $this->teams;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
||||
@@ -76,7 +76,7 @@ class Project implements EntityWithMetaFields
|
||||
*
|
||||
* @Serializer\Expose()
|
||||
* @Serializer\Groups({"Subresource", "Expanded"})
|
||||
* @SWG\Property(type="array", @SWG\Items(ref="#/definitions/Customer"))
|
||||
* @SWG\Property(ref="#/definitions/Customer")
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Customer")
|
||||
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
|
||||
|
||||
@@ -114,12 +114,27 @@ class Team
|
||||
* @ORM\ManyToMany(targetEntity="Project", mappedBy="teams", fetch="EXTRA_LAZY")
|
||||
*/
|
||||
private $projects;
|
||||
/**
|
||||
* Activities
|
||||
*
|
||||
* All activities assigned to the team
|
||||
*
|
||||
* @var Activity[]|ArrayCollection
|
||||
*
|
||||
* @Serializer\Expose()
|
||||
* @Serializer\Groups({"Team_Entity", "Expanded"})
|
||||
* @SWG\Property(type="array", @SWG\Items(ref="#/definitions/Activity"))
|
||||
*
|
||||
* @ORM\ManyToMany(targetEntity="Activity", mappedBy="teams", fetch="EXTRA_LAZY")
|
||||
*/
|
||||
private $activities;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->users = new ArrayCollection();
|
||||
$this->customers = new ArrayCollection();
|
||||
$this->projects = new ArrayCollection();
|
||||
$this->activities = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
@@ -256,6 +271,39 @@ class Team
|
||||
return $this->projects;
|
||||
}
|
||||
|
||||
public function hasActivity(Activity $activity): bool
|
||||
{
|
||||
return $this->activities->contains($activity);
|
||||
}
|
||||
|
||||
public function addActivity(Activity $activity)
|
||||
{
|
||||
if ($this->activities->contains($activity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->activities->add($activity);
|
||||
$activity->addTeam($this);
|
||||
}
|
||||
|
||||
public function removeActivity(Activity $activity)
|
||||
{
|
||||
if (!$this->activities->contains($activity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->activities->removeElement($activity);
|
||||
$activity->removeTeam($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<Activity>
|
||||
*/
|
||||
public function getActivities(): iterable
|
||||
{
|
||||
return $this->activities;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
||||
@@ -165,8 +165,8 @@ class Timesheet implements EntityWithMetaFields, ExportItemInterface
|
||||
* @var Activity
|
||||
*
|
||||
* @Serializer\Expose()
|
||||
* @Serializer\Groups({"Expanded"})
|
||||
* @SWG\Property(type="array", @SWG\Items(ref="#/definitions/ActivityExpanded"))
|
||||
* @Serializer\Groups({"Subresource", "Expanded"})
|
||||
* @SWG\Property(ref="#/definitions/ActivityExpanded")
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Activity")
|
||||
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
|
||||
@@ -180,7 +180,7 @@ class Timesheet implements EntityWithMetaFields, ExportItemInterface
|
||||
*
|
||||
* @Serializer\Expose()
|
||||
* @Serializer\Groups({"Subresource", "Expanded"})
|
||||
* @SWG\Property(type="array", @SWG\Items(ref="#/definitions/ProjectExpanded"))
|
||||
* @SWG\Property(ref="#/definitions/ProjectExpanded")
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Project")
|
||||
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
|
||||
|
||||
Reference in New Issue
Block a user