Remove NeptunUser and CookieModel
The app\models\NeptunUser
and app\models\CookieModel
classes were introduced in the initial commit of TMS v1 to handle the current locale, semester and controller (the latter corresponds to the role in today’s terminology, i.e. student or instructor) – at that time, all three were stored in cookies and only in cookies. Later, a new database column was added to the user table, which persisted the locale across sessions, but the locale of logged-out users as well as the semester and controller (role) of logged-in users continued to be stored in cookies. During the v2 rewrite, the app\controllers\BaseController
class, which used to set the NeptunUser
fields based on these cookies, was removed, and the locale of logged-out users as well as the currently selected semester and role are handled exclusively on client side, but app\models\NeptunUser
and app\models\CookieModel
remained.
They should be removed, changing the Yii::$app->user
to use the built-in yii\web\User
, for two reasons:
- Tech debt. Overriding the types of properties of
Yii::$app
makes the code harder to understand (it’s not obvious how to find out what the real type of a given property is) and confuses static analysis tools like PHPStan or IDEs. The naming is also problematic in light of #72. - Unnecessary cookies. Even though we never use the values of these cookies,
NeptunUser
still sets them on each login, which slightly increases the network traffic (the cookies are sent back with each request) and the storage usage in users’ browsers, without any benefit.
The fields of NeptunUser
are available from the request:
-
$locale
is sent in theAccept-Language
HTTP header and is available through the$acceptableLanguages
property of theyii\web\Request
object -
$semester
is sent as a query parameter where relevant -
$controller
is obvious from the fact that the controller of the given role is called (where relevant)