Added restrictions to user profile lists
This commit is contained in:
		
							parent
							
								
									66c56e9d02
								
							
						
					
					
						commit
						1d6137f7e2
					
				| 
						 | 
					@ -42,13 +42,19 @@ class EntityRepo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Get the latest books added to the system.
 | 
					     * Get the latest books added to the system.
 | 
				
			||||||
     * @param $count
 | 
					     * @param int $count
 | 
				
			||||||
     * @param $page
 | 
					     * @param int $page
 | 
				
			||||||
 | 
					     * @param bool $additionalQuery
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function getRecentlyCreatedBooks($count = 20, $page = 0)
 | 
					    public function getRecentlyCreatedBooks($count = 20, $page = 0, $additionalQuery = false)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return $this->restrictionService->enforceBookRestrictions($this->book)
 | 
					        $query = $this->restrictionService->enforceBookRestrictions($this->book)
 | 
				
			||||||
            ->orderBy('created_at', 'desc')->skip($page * $count)->take($count)->get();
 | 
					            ->orderBy('created_at', 'desc');
 | 
				
			||||||
 | 
					        if ($additionalQuery !== false && is_callable($additionalQuery)) {
 | 
				
			||||||
 | 
					            $additionalQuery($query);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return $query->skip($page * $count)->take($count)->get();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
| 
						 | 
					@ -65,13 +71,36 @@ class EntityRepo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Get the latest pages added to the system.
 | 
					     * Get the latest pages added to the system.
 | 
				
			||||||
     * @param $count
 | 
					     * @param int $count
 | 
				
			||||||
     * @param $page
 | 
					     * @param int $page
 | 
				
			||||||
 | 
					     * @param bool $additionalQuery
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function getRecentlyCreatedPages($count = 20, $page = 0)
 | 
					    public function getRecentlyCreatedPages($count = 20, $page = 0, $additionalQuery = false)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return $this->restrictionService->enforcePageRestrictions($this->page)
 | 
					        $query = $this->restrictionService->enforcePageRestrictions($this->page)
 | 
				
			||||||
            ->orderBy('created_at', 'desc')->skip($page * $count)->take($count)->get();
 | 
					            ->orderBy('created_at', 'desc');
 | 
				
			||||||
 | 
					        if ($additionalQuery !== false && is_callable($additionalQuery)) {
 | 
				
			||||||
 | 
					            $additionalQuery($query);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return $query->skip($page * $count)->take($count)->get();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Get the latest chapters added to the system.
 | 
				
			||||||
 | 
					     * @param int $count
 | 
				
			||||||
 | 
					     * @param int $page
 | 
				
			||||||
 | 
					     * @param bool $additionalQuery
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function getRecentlyCreatedChapters($count = 20, $page = 0, $additionalQuery = false)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $query = $this->restrictionService->enforceChapterRestrictions($this->chapter)
 | 
				
			||||||
 | 
					            ->orderBy('created_at', 'desc');
 | 
				
			||||||
 | 
					        if ($additionalQuery !== false && is_callable($additionalQuery)) {
 | 
				
			||||||
 | 
					            $additionalQuery($query);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return $query->skip($page * $count)->take($count)->get();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
| 
						 | 
					@ -100,7 +129,7 @@ class EntityRepo
 | 
				
			||||||
                foreach ($restrictions as $action => $value) {
 | 
					                foreach ($restrictions as $action => $value) {
 | 
				
			||||||
                    $entity->restrictions()->create([
 | 
					                    $entity->restrictions()->create([
 | 
				
			||||||
                        'role_id' => $roleId,
 | 
					                        'role_id' => $roleId,
 | 
				
			||||||
                        'action' => strtolower($action)
 | 
					                        'action'  => strtolower($action)
 | 
				
			||||||
                    ]);
 | 
					                    ]);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -141,12 +141,15 @@ class UserRepo
 | 
				
			||||||
    public function getRecentlyCreated(User $user, $count = 20)
 | 
					    public function getRecentlyCreated(User $user, $count = 20)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return [
 | 
					        return [
 | 
				
			||||||
            'pages' => $this->entityRepo->page->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
 | 
					            'pages'    => $this->entityRepo->getRecentlyCreatedPages($count, 0, function ($query) use ($user) {
 | 
				
			||||||
                ->take($count)->get(),
 | 
					                $query->where('created_by', '=', $user->id);
 | 
				
			||||||
            'chapters' => $this->entityRepo->chapter->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
 | 
					            }),
 | 
				
			||||||
                ->take($count)->get(),
 | 
					            'chapters' => $this->entityRepo->getRecentlyCreatedChapters($count, 0, function ($query) use ($user) {
 | 
				
			||||||
            'books' => $this->entityRepo->book->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
 | 
					                $query->where('created_by', '=', $user->id);
 | 
				
			||||||
                ->take($count)->get()
 | 
					            }),
 | 
				
			||||||
 | 
					            'books'    => $this->entityRepo->getRecentlyCreatedBooks($count, 0, function ($query) use ($user) {
 | 
				
			||||||
 | 
					                $query->where('created_by', '=', $user->id);
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -158,9 +161,9 @@ class UserRepo
 | 
				
			||||||
    public function getAssetCounts(User $user)
 | 
					    public function getAssetCounts(User $user)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return [
 | 
					        return [
 | 
				
			||||||
            'pages' => $this->entityRepo->page->where('created_by', '=', $user->id)->count(),
 | 
					            'pages'    => $this->entityRepo->page->where('created_by', '=', $user->id)->count(),
 | 
				
			||||||
            'chapters' => $this->entityRepo->chapter->where('created_by', '=', $user->id)->count(),
 | 
					            'chapters' => $this->entityRepo->chapter->where('created_by', '=', $user->id)->count(),
 | 
				
			||||||
            'books' => $this->entityRepo->book->where('created_by', '=', $user->id)->count(),
 | 
					            'books'    => $this->entityRepo->book->where('created_by', '=', $user->id)->count(),
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,8 +26,8 @@ class ActivityService
 | 
				
			||||||
     * Add activity data to database.
 | 
					     * Add activity data to database.
 | 
				
			||||||
     * @param Entity $entity
 | 
					     * @param Entity $entity
 | 
				
			||||||
     * @param        $activityKey
 | 
					     * @param        $activityKey
 | 
				
			||||||
     * @param int    $bookId
 | 
					     * @param int $bookId
 | 
				
			||||||
     * @param bool   $extra
 | 
					     * @param bool $extra
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function add(Entity $entity, $activityKey, $bookId = 0, $extra = false)
 | 
					    public function add(Entity $entity, $activityKey, $bookId = 0, $extra = false)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
| 
						 | 
					@ -45,7 +45,7 @@ class ActivityService
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Adds a activity history with a message & without binding to a entity.
 | 
					     * Adds a activity history with a message & without binding to a entity.
 | 
				
			||||||
     * @param            $activityKey
 | 
					     * @param            $activityKey
 | 
				
			||||||
     * @param int        $bookId
 | 
					     * @param int $bookId
 | 
				
			||||||
     * @param bool|false $extra
 | 
					     * @param bool|false $extra
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function addMessage($activityKey, $bookId = 0, $extra = false)
 | 
					    public function addMessage($activityKey, $bookId = 0, $extra = false)
 | 
				
			||||||
| 
						 | 
					@ -88,7 +88,7 @@ class ActivityService
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function latest($count = 20, $page = 0)
 | 
					    public function latest($count = 20, $page = 0)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $activityList =  $this->restrictionService
 | 
					        $activityList = $this->restrictionService
 | 
				
			||||||
            ->filterRestrictedEntityRelations($this->activity, 'activities', 'entity_id', 'entity_type')
 | 
					            ->filterRestrictedEntityRelations($this->activity, 'activities', 'entity_id', 'entity_type')
 | 
				
			||||||
            ->orderBy('created_at', 'desc')->skip($count * $page)->take($count)->get();
 | 
					            ->orderBy('created_at', 'desc')->skip($count * $page)->take($count)->get();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -99,8 +99,8 @@ class ActivityService
 | 
				
			||||||
     * Gets the latest activity for an entity, Filtering out similar
 | 
					     * Gets the latest activity for an entity, Filtering out similar
 | 
				
			||||||
     * items to prevent a message activity list.
 | 
					     * items to prevent a message activity list.
 | 
				
			||||||
     * @param Entity $entity
 | 
					     * @param Entity $entity
 | 
				
			||||||
     * @param int    $count
 | 
					     * @param int $count
 | 
				
			||||||
     * @param int    $page
 | 
					     * @param int $page
 | 
				
			||||||
     * @return array
 | 
					     * @return array
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function entityActivity($entity, $count = 20, $page = 0)
 | 
					    public function entityActivity($entity, $count = 20, $page = 0)
 | 
				
			||||||
| 
						 | 
					@ -121,9 +121,10 @@ class ActivityService
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function userActivity($user, $count = 20, $page = 0)
 | 
					    public function userActivity($user, $count = 20, $page = 0)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $activity = $this->activity->where('user_id', '=', $user->id)
 | 
					        $activityList = $this->restrictionService
 | 
				
			||||||
            ->orderBy('created_at', 'desc')->skip($count * $page)->take($count)->get();
 | 
					            ->filterRestrictedEntityRelations($this->activity, 'activities', 'entity_id', 'entity_type')
 | 
				
			||||||
        return $this->filterSimilar($activity);
 | 
					            ->orderBy('created_at', 'desc')->where('user_id', '=', $user->id)->skip($count * $page)->take($count)->get();
 | 
				
			||||||
 | 
					        return $this->filterSimilar($activityList);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue