~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to lib/Controller/User.php

  • Committer: Dan Garner
  • Date: 2018-05-21 14:58:11 UTC
  • mfrom: (644.1.8)
  • mto: (614.1.6)
  • mto: This revision was merged to the branch mainline in revision 648.
  • Revision ID: git-v1:e7961b0ebe68a0c0bc5dd7b3abca007138b2cadd
Merge branch 'bugfix/1.8.10-pack1' into feature/r-graph

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
use Xibo\Entity\Campaign;
24
24
use Xibo\Entity\Layout;
 
25
use Xibo\Entity\Media;
25
26
use Xibo\Entity\Permission;
26
27
use Xibo\Entity\Playlist;
27
28
use Xibo\Entity\Region;
29
30
use Xibo\Exception\AccessDeniedException;
30
31
use Xibo\Exception\ConfigurationException;
31
32
use Xibo\Exception\InvalidArgumentException;
 
33
use Xibo\Exception\XiboException;
32
34
use Xibo\Factory\ApplicationFactory;
33
35
use Xibo\Factory\CampaignFactory;
34
36
use Xibo\Factory\DisplayFactory;
37
39
use Xibo\Factory\PageFactory;
38
40
use Xibo\Factory\PermissionFactory;
39
41
use Xibo\Factory\ScheduleFactory;
 
42
use Xibo\Factory\SessionFactory;
40
43
use Xibo\Factory\UserFactory;
41
44
use Xibo\Factory\UserGroupFactory;
42
45
use Xibo\Factory\UserTypeFactory;
105
108
    /** @var  DisplayFactory */
106
109
    private $displayFactory;
107
110
 
 
111
    /** @var SessionFactory */
 
112
    private $sessionFactory;
 
113
 
108
114
    /**
109
115
     * Set common dependencies.
110
116
     * @param LogServiceInterface $log
125
131
     * @param MediaFactory $mediaFactory
126
132
     * @param ScheduleFactory $scheduleFactory
127
133
     * @param DisplayFactory $displayFactory
 
134
     * @param SessionFactory $sessionFactory
128
135
     */
129
136
    public function __construct($log, $sanitizerService, $state, $user, $help, $date, $config, $userFactory,
130
137
                                $userTypeFactory, $userGroupFactory, $pageFactory, $permissionFactory,
131
 
                                $layoutFactory, $applicationFactory, $campaignFactory, $mediaFactory, $scheduleFactory, $displayFactory)
 
138
                                $layoutFactory, $applicationFactory, $campaignFactory, $mediaFactory, $scheduleFactory, $displayFactory, $sessionFactory)
132
139
    {
133
140
        $this->setCommonDependencies($log, $sanitizerService, $state, $user, $help, $date, $config);
134
141
 
143
150
        $this->mediaFactory = $mediaFactory;
144
151
        $this->scheduleFactory = $scheduleFactory;
145
152
        $this->displayFactory = $displayFactory;
 
153
        $this->sessionFactory = $sessionFactory;
146
154
    }
147
155
 
148
156
    /**
246
254
 
247
255
            $user->libraryQuotaFormatted = ByteFormatter::format($user->libraryQuota * 1024);
248
256
 
 
257
            $user->loggedIn = $this->sessionFactory->getActiveSessionsForUser($user->userId);
 
258
            $this->getLog()->debug('Logged in status for user ID ' . $user->userId . ' with name ' . $user->userName . ' is ' . $user->loggedIn);
 
259
 
249
260
            if ($this->isApi())
250
261
                break;
251
262
 
844
855
     *
845
856
     * @param string $entity
846
857
     * @param int $objectId
847
 
     * @throws ConfigurationException
 
858
     * @throws XiboException
848
859
     */
849
860
    public function permissions($entity, $objectId)
850
861
    {
929
940
 
930
941
                $updatePermissionsOnLayout($layout);
931
942
            }
 
943
        } else if ($object->permissionsClass() == 'Xibo\Entity\Region') {
 
944
            // We always cascade region permissions down to the Playlist
 
945
            // TODO: we should change this to $object->regionPlaylist in 2.0
 
946
            $object->load();
 
947
 
 
948
            foreach ($object->playlists as $playlist) {
 
949
                /* @var Playlist $playlist */
 
950
                $this->updatePermissions($this->permissionFactory->getAllByObjectId($this->getUser(), get_class($playlist), $playlist->getId()), $groupIds);
 
951
            }
 
952
        } else if ($object->permissionsClass() == 'Xibo\Entity\Media') {
 
953
            // Are we a font?
 
954
            /** @var $object Media */
 
955
            if ($object->mediaType === 'font') {
 
956
                // Drop permissions (we need to reassess).
 
957
                $this->getApp()->container->get('\Xibo\Controller\Library')->setApp($this->getApp())->installFonts(['invalidateCache' => true]);
 
958
            }
932
959
        }
933
960
 
934
961
        // Return
1169
1196
            'id' => $user->userId
1170
1197
        ]);
1171
1198
    }
 
1199
 
 
1200
    /**
 
1201
     * Update the User Welcome Tutorial to Seen
 
1202
     */
 
1203
    public function userWelcomeSetUnSeen()
 
1204
    {
 
1205
        $this->getUser()->newUserWizard = 0;
 
1206
        $this->getUser()->save(['validate' => false]);
 
1207
 
 
1208
        // Return
 
1209
        $this->getState()->hydrate([
 
1210
            'httpStatus' => 204,
 
1211
            'message' => sprintf(__('%s has started the welcome tutorial'), $this->getUser()->userName)
 
1212
        ]);
 
1213
    }
 
1214
 
 
1215
    /**
 
1216
     * Update the User Welcome Tutorial to Seen
 
1217
     */
 
1218
    public function userWelcomeSetSeen()
 
1219
    {
 
1220
        $this->getUser()->newUserWizard = 1;
 
1221
        $this->getUser()->save(['validate' => false]);
 
1222
 
 
1223
        // Return
 
1224
        $this->getState()->hydrate([
 
1225
            'httpStatus' => 204,
 
1226
            'message' => sprintf(__('%s has seen the welcome tutorial'), $this->getUser()->userName)
 
1227
        ]);
 
1228
    }
1172
1229
}