Skip to content

Commit 0c38d52

Browse files
authored
Merge pull request #804 from CalamityC/catalogs_view_filter
Catalogs view should filter by site #801
2 parents f7c0972 + 4b85c48 commit 0c38d52

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

rdmo/management/assets/js/store/configureStore.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { applyMiddleware, createStore } from 'redux'
2+
import Cookies from 'js-cookie'
23
import thunk from 'redux-thunk'
4+
import isEmpty from 'lodash/isEmpty'
35
import isNil from 'lodash/isNil'
46

57
import { parseLocation } from '../utils/location'
@@ -12,6 +14,15 @@ import * as elementActions from '../actions/elementActions'
1214
export default function configureStore() {
1315
const middlewares = [thunk]
1416

17+
// empty localStorage in new session
18+
const currentStoreId = Cookies.get('storeid')
19+
const localStoreId = localStorage.getItem('rdmo.storeid')
20+
21+
if (isEmpty(localStoreId) || localStoreId !== currentStoreId) {
22+
localStorage.clear()
23+
localStorage.setItem('rdmo.storeid', currentStoreId)
24+
}
25+
1526
if (process.env.NODE_ENV === 'development') {
1627
const { logger } = require('redux-logger')
1728
middlewares.push(logger)
@@ -28,7 +39,6 @@ export default function configureStore() {
2839
// load: restore the config from the local storage
2940
const updateConfigFromLocalStorage = () => {
3041
const ls = {...localStorage}
31-
3242
Object.entries(ls).forEach(([lsPath, lsValue]) => {
3343
const path = lsPath.replace('rdmo.management.config.', '')
3444
let value
@@ -46,9 +56,11 @@ export default function configureStore() {
4656
})
4757
}
4858

59+
let currentSiteId
4960
// load, popstate: fetch elements depending on the location
5061
const fetchElementsFromLocation = () => {
5162
const baseUrl = store.getState().config.baseUrl
63+
currentSiteId = store.getState().config.currentSite?.id.toString() || ''
5264
const pathname = window.location.pathname
5365
let { elementType, elementId, elementAction } = parseLocation(baseUrl, pathname)
5466

@@ -69,7 +81,13 @@ export default function configureStore() {
6981
// this event is triggered when the page first loads
7082
window.addEventListener('load', () => {
7183
updateConfigFromLocalStorage()
72-
fetchConfig().then(() => fetchElementsFromLocation())
84+
fetchConfig().then(() => {
85+
fetchElementsFromLocation()
86+
if (!isEmpty(currentSiteId) && isEmpty(store.getState().config.filter) && store.getState().config.settings.multisite) {
87+
store.dispatch(configActions.updateConfig('filter.sites', currentSiteId))
88+
}
89+
})
90+
7391
})
7492

7593
// this event is triggered when when the forward/back buttons are used

rdmo/management/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import hashlib
12
import logging
23

34
from django.contrib.auth.mixins import LoginRequiredMixin
@@ -18,3 +19,10 @@ class ManagementView(LoginRequiredMixin, PermissionRedirectMixin, RulesPermissio
1819
def has_permission(self):
1920
# Use test_rule from rules for permissions check
2021
return test_rule('management.can_view_management', self.request.user, self.request.site)
22+
23+
def render_to_response(self, context, **response_kwargs):
24+
storeid = hashlib.sha256(self.request.session.session_key.encode()).hexdigest()
25+
26+
response = super().render_to_response(context, **response_kwargs)
27+
response.set_cookie('storeid', storeid)
28+
return response

0 commit comments

Comments
 (0)