8000 Bugfix v4: Structure mode toggle button disappearing from toolbar by fsbraun · Pull Request #7272 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

Bugfix v4: Structure mode toggle button disappearing from toolbar #7272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c4fae50
Actions: run gulp build
fsbraun Mar 23, 2022
0151b22
Add console.log
fsbraun Mar 23, 2022
6075489
Add: github actions artifacts and see if it runs with node 10
fsbraun Mar 23, 2022
35735a9
Fix: missing comma in yaml
fsbraun Mar 23, 2022
0281288
Back to node@6
fsbraun Mar 23, 2022
05a8d8e
Merge branch 'django-cms:develop-4' into develop-4
fsbraun Mar 23, 2022
9421e08
Fix: Structure board button disappearing after changing a page's con…
fsbraun Mar 23, 2022
d7cb809
Fix: Undo other debug changes
fsbraun Mar 23, 2022
1a8d642
Fix: Re-add cms_path to toolbar url
fsbraun Mar 23, 2022
a6390d5
Fix: Broken test
fsbraun Mar 23, 2022
b405c94
Fix: lint errors
fsbraun Mar 23, 2022
6078f40
Fix: Improved responisveness by saving an unecessary xhr call for th…
fsbraun Mar 23, 2022
385e38a
Tribute to eslint
fsbraun Mar 23, 2022
8cd900e
Fix: get_toolbar xhr call needs to resolve to the cms_path not the r…
fsbraun Mar 23, 2022
2bc18ac
Add: Test for invalid toolbar resolver path
fsbraun Mar 24, 2022
c106f59
Change: Buggy Helpers.updateUrlWithPath. Works fine as long as only …
fsbraun Mar 24, 2022
7da41c7
Fix: toolbar py test
fsbraun Mar 25, 2022
12e09d5
Merge branch 'develop-4' into develop-4
Aiky30 May 18, 2022
966fe39
Update cms/static/cms/js/modules/cms.structureboard.js
fsbraun May 18, 2022
3bc9808
Update cms/static/cms/js/modules/cms.toolbar.js
fsbraun May 18, 2022
330d333
Update cms/tests/test_toolbar.py
fsbraun May 18, 2022
0ed88e1
Update cms.base.js
fsbraun May 18, 2022
760d4bb
Update cms.base.js
fsbraun May 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cms/admin/settingsadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.db import transaction
from django.http import HttpResponseRedirect, HttpResponse, HttpResponseBadRequest
from django.http.request import QueryDict
from django.urls import re_path
from django.urls import re_path, resolve, Resolver404
from django.utils.html import conditional_escape
from django.utils.translation import override

Expand Down Expand Up @@ -97,6 +97,10 @@ def get_toolbar(self, request):
request = copy.copy(request)
request.GET = data
request.current_page = current_page
try:
request.resolver_match = resolve(origin_url.path)
except Resolver404:
pass
request.toolbar = CMSToolbar(request, request_path=origin_url.path, _async=True)
request.toolbar.set_object(attached_obj or current_page)
return HttpResponse(request.toolbar.render())
Expand Down
11 changes: 3 additions & 8 deletions cms/static/cms/js/modules/cms.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ export const Helpers = {
},

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

return newUrl
.toString()
.split('#')
.map((part, i) => {
return i === 0 ? part.replace(/&/g, '&') : part;
})
.join('#');
.toString();
},

/**
Expand Down
20 changes: 9 additions & 11 deletions cms/static/cms/js/modules/cms.structureboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -997,26 +997,24 @@ class StructureBoard {
// refresh toolbar
var currentMode = CMS.settings.mode;

this._loadToolbar()
.done(newToolbar => {
CMS.API.Toolbar._refreshMarkup($(newToolbar).find('.cms-toolbar'));
})
.fail(() => Helpers.reloadBrowser());

if (currentMode === 'structure') {
this._requestcontent = null;

if (this._loadedContent && action !== 'COPY') {
this.updateContent();
return; // Toolbar loaded
}
return;
}

// invalidate the content mode
if (action !== 'COPY') {
} else if (action !== 'COPY') {
this._requestcontent = null;
this.updateContent();
return; // Toolbar loaded

}
this._loadToolbar()
.done(newToolbar => {
CMS.API.Toolbar._refreshMarkup($(newToolbar).find('.cms-toolbar'));
})
.fail(() => Helpers.reloadBrowser());
}

_propagateInvalidatedState(action, data) {
Expand Down
30 changes: 15 additions & 15 deletions cms/tests/frontend/unit/cms.base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,45 +549,45 @@ describe('cms.base.js', function() {
var url;

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

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

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

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

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

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

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

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

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

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

url = CMS.API.Helpers.makeURL('test#hash#with#hash', [['param', '1'], ['anoth 6DB6 er', '2']]);
expect(url).toEqual('test?param=1&another=2#hash#with#hash');
expect(url).toEqual('test?param=1&another=2#hash#with#hash');

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

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

url = CMS.API.Helpers.makeURL('test#hash&stuff', []);
expect(url).toEqual('test#hash&stuff');
Expand Down
2 changes: 1 addition & 1 deletion cms/tests/frontend/unit/cms.structureboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,7 @@ describe('CMS.StructureBoard', function() {

expect($.ajax).toHaveBeenCalledWith({
url: jasmine.stringMatching(
/TOOLBAR_URL\?obj_id=100&obj_type=cms.page&cms_path=%2Fstructure*/
/TOOLBAR_URL\?obj_id=100&obj_type=cms.page&cms_path=%2Fstructure*/
)
});
});
Expand Down
13 changes: 13 additions & 0 deletions cms/tests/test_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,19 @@ def test_toolbar_request_endpoint_validation(self):
},
)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Clipboard")

response = self.client.get(
endpoint,
data={
'obj_id': page_content.pk,
'obj_type': 'cms.pagecontent',
'cms_path': get_object_edit_url(page_content)+"q" # Invalid
},
)
self.assertEqual(response.status_code, 200)
# No clipboard exposed to invalid cms_path
self.assertNotContains(response, "Clipboard")

# Invalid app / model
response = self.client.get(
Expand Down
6 changes: 1 addition & 5 deletions cms/toolbar/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,7 @@ def __init__(self, request, request_path=None, _async=False):
try:
# If the original view is decorated we try to extract the real function
# module instead of the decorator's one
if decorator and getattr(decorator, 'func_closure', False):
# python 2
self.app_name = decorator.func_closure[0].cell_contents.__module__
elif decorator and getattr(decorator, '__closure__', False):
# python 3
if decorator and getattr(decorator, '__closure__', False):
self.app_name = decorator.__closure__[0].cell_contents.__module__
else:
raise AttributeError()
Expand Down
0