Django-cms ckeditor permissions - django

We are developing a django-cms (django 1.8, cms 3.2) site including the ckeditor. Logging in with admin, no problems. But when I set a user to staff and give PagePermissions, I get the error "You do not have permission to edit this plugin", when opening the editor in cms. What am I missing?

please update the details:
Where i understood it might be because of this:
The problem is that after migrating to ckeditor, the relevant permissions in auth_permissions, as stated above, point to the wrong content type id. To fix this problem look up the id of the ckeditorplugin content type:
select * from django_content_type where app_label = 'djangocms_text_ckeditor';
and the original text plugin:
select * from django_content_type where app_label = 'text';
Now update the relevant permissions:
update auth_permission set content_type_id = <new ck text plugin id> where content_type_id = <old text plugin id>;

Non superusers must also be provided permission on individual plugins, for them to be able to add/edit/delete them.
Non superusers must also have "use structure mode" permission (starting 3.1+) to enter structure mode in the frontend editor.
The best way to give users permission on pages is by using the "Permissions" item in the toolbar on the page you want to give permission to: it's the best way to be sure to provide all the needed permissions on the correct page.

Related

How to get site settings in a django project converted to wagtail

I have a django site onto which I have added wagtail following these instructions.
I have set up Social Media setting using these instructions
I have sucessfully added details on the admin page ad I can return and edit these details
However I cannot access them in a template
If I display
{{settings.site_settings.SiteSettings.facebook}}
I get '' (tested using {% if settings.site_settings.SiteSettings.facebook == '' ...)
However
{{settings.site_settings.SiteSettings}}
returns None
and
{{settings.site_settings}}
returns SettingsModuleProxy(site_settings)
What am I doing wrong?
The problem was simply that I had misspelt the SiteSettings class name in models.py (very red-face)

In the Wagtail how to disable certain admin menu items for the certain users?

For the group of users I want to disable some menu items. I thought I will use the following:
from wagtail.contrib.modeladmin.options import ModelAdmin as WModelAdmin
class WPartnerAdmin(WModelAdmin):
...
def get_menu_item(self, order=None):
menu_item = super().get_menu_item(order=order)
# if (user_discrimination_logic):
# menu_item.is_shown = lambda *a: False
return menu_item
But it seems that I don’t have access to the request object in the Wagtail ModelAdmin, therefore don’t know how to extract the user data. Is there a way?
You can use Wagtail's Hooks functionality, particularly the construct_main_menu hook:
Create a wagtail_hooks.py file in your corresponding application, with something like the following (from the Wagtail Docs):
from wagtail.core import hooks
#hooks.register('construct_main_menu')
def hide_explorer_menu_item_from_frank(request, menu_items):
if request.user.username == 'frank':
menu_items[:] = [item for item in menu_items if item.name != 'explorer']
Wagtail's built in permission system stops the user from viewing the actual modeladmin objects, but the available options still show up in the menu even for groups without permission to view them. When they try to view the objects, people without view permission are sent to the login screen and told they have insufficient permission.
If you want to hide admin menu items for particular users that are all part of a specific group, or even multiple groups, you can do it using wagtail's construct_main_menu hook. Add a wagtail_hooks.py file in the app folder. Menu items are edited in place.
To remove two menu items called "secrets1" and "secrets2" for users that are in any of "regular_user" or "bad_user" groups, you could do something like this:
from wagtail.core import hooks
#hooks.register('construct_main_menu')
def hide_explorer_items_from_users(request, menu_items):
if request.user.groups.filter(name__in=["regular_user", "bad_user"]):
menu_items[:] = [
item for item in menu_items if item.name not in ['secrets1', 'secrets2']
]
This is fine for removing items, but if plan on adding menu items this way, Wagtail's Hooks Documentation warns you that menu items added this way will be missing associated javascript includes, so you should use the #register_admin_menu_item hook for adding items instead.
For most purposes, this can be done without any code changes, through the permissions system.
Under Settings -> Groups, define a group with permissions over the objects they should be able to edit (such as pages, images and documents), and ensure the 'Can access Wagtail admin' permission is checked. Then, in Settings -> Users, go to the Roles tab for each user and add them to that group (and ensure Administrator is unchecked). Any menu items that the user doesn't have permission over will be hidden.

ckeditor field shows html tags in content only when value not changed

I am supporting an ember site that was build by someone else. The frontend is Emberjs with a Drupal 7 backend.
The site has a user profile where they can enter a bio. The initial bio entry is fine, but if the user edits the profile (changes some other field for example) but does not change the bio text, then it saves something like <p>My bio</p>as the value of the field where the html tags are saved as text.
The component.js for the form has this in it:
bodyChanged(newValue) {
this.get('profile').set('bio', newValue);
},
Suspecting this is the culprit but not sure what to do to fix.
Thanks
I found the problem. My deserializing function that sucks in the drupal json was using json[fieldName]['und'][0]['safe_value']; as the value. When I switched it to use the json[fieldName]['und'][0]['value']; the problem went away.

django-tables2 and LinkColumn. Correct path to Django-admin site page

I am developing cmdb application and trying to create a link to admin page of the device ( /admin/cmdb/device/device_id/) in django-tables2 LinkColumn with the following syntax:
id = tables.LinkColumn('admin:cmdb:device', args=[A('pk')])
This fails with error
NoReverseMatch at /cmdb/emp/171/
'cmdb' is not a registered namespace inside 'admin'
(/cmdb/emp/171/ - is the page on which the table is rendered)
How can I write the correct path in LinkColumn argument to Django admin page?
The goal could be achieved by using TemplateColumn:
id2 = tables.TemplateColumn('{{record.id}}')
but possibly someone could advise how to use LinkColumn?
Your question is not about the LinkColumn but about finding out the url names of the django admin pages.
In any case, you can find your answer here: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#reversing-admin-urls
So if the name of your application is cmdb and the name of your model is device, the url name of the device edit page would be admin:cmdb_device_change which could be used in the LinkColumn (also it can be used in the TemplateColumn using {% url "admin:cmdb_device_chang" record.id %}).

Opencart product.tpl

Where did I miss to add a line of code if I try to echo php variable inside OPENCART product.tpl file and it doesn't show up on site?
Notes: there is a field in database. I am able to save to this field from admin panel ( i added a custom field there).
Did You edit also the product controller to load the variable and pass it to the template? I guess not... Edit catalog/controller/product/product.php and add $this->data['MYVARIABLE'] = $product_info['MYVARIABLE']; somewhere before $this->render() is called.