8000 fix: Structure mode toggle button disappearing from toolbar (#7272) · django-cms/django-cms@7dafe84 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7dafe84

Browse files
authored
fix: Structure mode toggle button disappearing from toolbar (#7272)
1 parent 98959dc commit 7dafe84

File tree

7 files changed

+47
-41
lines changed

7 files changed

+47
-41
lines changed

cms/admin/settingsadmin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from django.db import transaction
1111
from django.http import HttpResponseRedirect, HttpResponse, HttpResponseBadRequest
1212
from django.http.request import QueryDict
13-
from django.urls import re_path
13+
from django.urls import re_path, resolve, Resolver404
1414
from django.utils.html import conditional_escape
1515
from django.utils.translation import override
1616

@@ -97,6 +97,10 @@ def get_toolbar(self, request):
9797
request = copy.copy(request)
9898
request.GET = data
9999
request.current_page = current_page
100+
try:
101+
request.resolver_match = resolve(origin_url.path)
102+
except Resolver404:
103+
pass
100104
request.toolbar = CMSToolbar(request, request_path=origin_url.path, _async=True)
101105
request.toolbar.set_object(attached_obj or current_page)
102106
return HttpResponse(request.toolbar.render())

cms/static/cms/js/modules/cms.base.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ export const Helpers = {
280280
},
281281

282282
/**
283-
* Modifies the url with new params and sanitises
284-
* the ampersand within the url for #3404.
283+
* Modifies the url with new params and sanitises the url
284+
* reversing any & to ampersand (introduced with #3404)
285285
*
286286
* @method makeURL
287287
* @param {String} url original url
@@ -299,12 +299,7 @@ export const Helpers = {
299299
});
300300

301301
return newUrl
302-
.toString()
303-
.split('#')
304-
.map((part, i) => {
305-
return i === 0 ? part.replace(/&/g, '&') : part;
306-
})
307-
.join('#');
302+
.toString();
308303
},
309304

310305
/**

cms/static/cms/js/modules/cms.structureboard.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -997,26 +997,24 @@ class StructureBoard {
997997
// refresh toolbar
998998
var currentMode = CMS.settings.mode;
999999

1000-
this._loadToolbar()
1001-
.done(newToolbar => {
1002-
CMS.API.Toolbar._refreshMarkup($(newToolbar).find('.cms-toolbar'));
1003-
})
1004-
.fail(() => Helpers.reloadBrowser());
1005-
10061000
if (currentMode === 'structure') {
10071001
this._requestcontent = null;
10081002

10091003
if (this._loadedContent && action !== 'COPY') {
10101004
this.updateContent();
1005+
return; // Toolbar loaded
10111006
}
1012-
return;
1013-
}
1014-
1015-
// invalidate the content mode
1016-
if (action !== 'COPY') {
1007+
} else if (action !== 'COPY') {
10171008
this._requestcontent = null;
10181009
this.updateContent();
1010+
return; // Toolbar loaded
1011+
10191012
}
1013+
this._loadToolbar()
1014+
.done(newToolbar => {
1015+
CMS.API.Toolbar._refreshMarkup($(newToolbar).find('.cms-toolbar'));
1016+
})
1017+
.fail(() => Helpers.reloadBrowser());
10201018
}
10211019

10221020
_propagateInvalidatedState(action, data) {

cms/tests/frontend/unit/cms.base.test.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -549,45 +549,45 @@ describe('cms.base.js', function() {
549549
var url;
550550

551551
url = CMS.API.Helpers.makeURL('test', [['param', '1'], ['another', '2']]);
552-
expect(url).toEqual('test?param=1&another=2');
552+
expect(url).toEqual('test?param=1&another=2');
553553

554554
url = CMS.API.Helpers.makeURL('test?param=1', [['another', '2']]);
555-
expect(url).toEqual('test?param=1&another=2');
555+
expect(url).toEqual('test?param=1&another=2');
556556

557557
url = CMS.API.Helpers.makeURL('test?param=1&another=2', [['different', '3']]);
558-
expect(url).toEqual('test?param=1&another=2&different=3');
558+
expect(url).toEqual('test?param=1&another=2&different=3');
559559

560-
url = CMS.API.Helpers.makeURL('test?param=1&another=2', [['different', '3']]);
561-
expect(url).toEqual('test?param=1&another=2&different=3');
560+
url = CMS.API.Helpers.makeURL('test?param=1&another=2', [['different', '3']]);
561+
expect(url).toEqual('test?param=1&another=2&different=3');
562562

563-
url = CMS.API.Helpers.makeURL('test?param=1&another=2&again=3', [['different', '3']]);
564-
expect(url).toEqual('test?param=1&another=2&again=3&different=3');
563+
url = CMS.API.Helpers.makeURL('test?param=1&another=2&again=3', [['different', '3']]);
564+
expect(url).toEqual('test?param=1&another=2&again=3&different=3');
565565
});
566566

567567
it('replaces param values with new ones if they match', function() {
568568
var url;
569569

570-
url = CMS.API.Helpers.makeURL('test?param=1&another=2', [['another', '3']]);
571-
expect(url).toEqual('test?param=1&another=3');
570+
url = CMS.API.Helpers.makeURL('test?param=1&another=2', [['another', '3']]);
571+
expect(url).toEqual('test?param=1&another=3');
572572

573-
url = CMS.API.Helpers.makeURL('test?param=1&another=2', [['another', '3'], ['param', '4']]);
574-
expect(url).toEqual('test?another=3&param=4');
573+
url = CMS.API.Helpers.makeURL('test?param=1&another=2', [['another', '3'], ['param', '4']]);
574+
expect(url).toEqual('test?another=3&param=4');
575575
});
576576

577577
it('understands hashes in the url', function() {
578578
var url;
579579

580580
url = CMS.API.Helpers.makeURL('test#hash', [['param', '1'], ['another', '2']]);
581-
expect(url).toEqual('test?param=1&another=2#hash');
581+
expect(url).toEqual('test?param=1&another=2#hash');
582582

583583
url = CMS.API.Helpers.makeURL('test#hash#with#hash', [['param', '1'], ['another', '2']]);
584-
expect(url).toEqual('test?param=1&another=2#hash#with#hash');
584+
expect(url).toEqual('test?param=1&another=2#hash#with#hash');
585585

586586
url = CMS.API.Helpers.makeURL('test#', [['param', '1'], ['another', '2']]);
587-
expect(url).toEqual('test?param=1&another=2');
587+
expect(url).toEqual('test?param=1&another=2');
588588

589589
url = CMS.API.Helpers.makeURL('test#hash&stuff', [['param', '1'], ['another', '2']]);
590-
expect(url).toEqual('test?param=1&another=2#hash&stuff');
590+
expect(url).toEqual('test?param=1&another=2#hash&stuff');
591591

592592
url = CMS.API.Helpers.makeURL('test#hash&stuff', []);
593593
expect(url).toEqual('test#hash&stuff');

cms/tests/frontend/unit/cms.structureboard.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2125,7 +2125,7 @@ describe('CMS.StructureBoard', function() {
21252125

21262126
expect($.ajax).toHaveBeenCalledWith({
21272127
url: jasmine.stringMatching(
2128-
/TOOLBAR_URL\?obj_id=100&obj_type=cms.page&cms_path=%2Fstructure*/
2128+
/TOOLBAR_URL\?obj_id=100&obj_type=cms.page&cms_path=%2Fstructure*/
21292129
)
21302130
});
21312131
});

cms/tests/test_toolbar.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,19 @@ def test_toolbar_request_endpoint_validation(self):
200200
},
201201
)
202202
self.assertEqual(response.status_code, 200)
203+
self.assertContains(response, "Clipboard")
204+
205+
response = self.client.get(
206+
endpoint,
207+
data={
208+
'obj_id': page_content.pk,
209+
'obj_type': 'cms.pagecontent',
210+
'cms_path': get_object_edit_url(page_content)+"q" # Invalid
211+
},
212+
)
213+
self.assertEqual(response.status_code, 200)
214+
# No clipboard exposed to invalid cms_path
215+
self.assertNotContains(response, "Clipboard")
203216

204217
# Invalid app / model
205218
response = self.client.get(

cms/toolbar/toolbar.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,7 @@ def __init__(self, request, request_path=None, _async=False):
163163
try:
164164
# If the original view is decorated we try to extract the real function
165165
# module instead of the decorator's one
166-
if decorator and getattr(decorator, 'func_closure', False):
167-
# python 2
168-
self.app_name = decorator.func_closure[0].cell_contents.__module__
169-
elif decorator and getattr(decorator, '__closure__', False):
170-
# python 3
166+
if decorator and getattr(decorator, '__closure__', False):
171167
self.app_name = decorator.__closure__[0].cell_contents.__module__
172168
else:
173169
raise AttributeError()

0 commit comments

Comments
 (0)
0