66
77import { ref } from "vue" ;
88import SecurityAdvisoriesService from "@/services/security-advisories-service" ;
9+ import { useUserStore } from "@/stores/UserState" ;
910
1011const DISMISSED_KEY = "advisory_dismissed" ;
1112
@@ -21,25 +22,33 @@ const advisories = ref<App.Http.Resources.Models.SecurityAdvisoryResource[]>([])
2122 * modal for admin users after login.
2223 *
2324 * The modal is shown at most once per browser session (controlled via
24- * sessionStorage). Non-admin users receive a 403 from the endpoint, which
25- * is caught and silently ignored .
25+ * sessionStorage). The advisory endpoint is only queried when the current
26+ * user has the `may_administrate` flag set on their user resource .
2627 */
2728export function useAdvisoryModal ( ) {
2829 function advisoryCheck ( ) {
29- if ( sessionStorage . getItem ( DISMISSED_KEY ) !== null ) {
30- return ;
31- }
32-
33- SecurityAdvisoriesService . getAdvisories ( )
34- . then ( ( response ) => {
35- if ( response . data . length > 0 ) {
36- advisories . value = response . data ;
37- isAdvisoriesVisible . value = true ;
38- }
39- } )
40- . catch ( ( ) => {
41- // 401/403 for non-admins or network errors: silently ignore.
42- } ) ;
30+ const userStore = useUserStore ( ) ;
31+
32+ userStore . load ( ) . then ( ( ) => {
33+ if ( ! userStore . isAdmin ) {
34+ return ;
35+ }
36+
37+ if ( sessionStorage . getItem ( DISMISSED_KEY ) !== null ) {
38+ return ;
39+ }
40+
41+ SecurityAdvisoriesService . getAdvisories ( )
42+ . then ( ( response ) => {
43+ if ( response . data . length > 0 ) {
44+ advisories . value = response . data ;
45+ isAdvisoriesVisible . value = true ;
46+ }
47+ } )
48+ . catch ( ( ) => {
49+ // Network errors: silently ignore.
50+ } ) ;
51+ } ) ;
4352 }
4453
4554 function advisoryDismiss ( ) {
0 commit comments