Пример #1
0
  def register_action(cls, app):
    actions = util.get_attr_from('%s.urls.urlpatterns' % app)
    
    items_excluded = util.get_config_value(app, 'exclude_auth', [])

    # Get all actions from app
    actions_list_name = []
    for action in actions:
      if action.name:
        authorizable = action.name not in items_excluded and True
        action_ref = cls.get(appname=app, name=action.name)
        if not action_ref:
          action_ref = cls(appname=app,
                           name=action.name,
                           pattern=action.regex.pattern,
                           authorizable=authorizable)
        else:
          action_ref.authorizable = authorizable
        action_ref.put()
        actions_list_name.append(action.name)
        
    default_auth = util.get_config_value(app, 'default_auth', {'administrator':actions_list_name})

    # Create permissions
    for role, items in default_auth.iteritems():
      permission_ref = Permission.get_by_role(role)
      if items == '*':
        app_actions = [x for x in actions_list_name if x not in permission_ref.actions]
      else:
        app_actions = [x for x in items if x not in permission_ref.actions]
      permission_ref.actions += app_actions
      permission_ref.save()
Пример #2
0
  def process_request(self, request):
    if not ConfigData.get_configdata('site_installed', default=False):
      theming.check_themes()
      if not request.path.startswith('/install') and not request.path.startswith('/loader'):
        return http.HttpResponseRedirect(reverse('install'))
      
    if not request.path.startswith('/install') and not request.path.startswith('/loader'):
      for app in settings.INSTALLED_APPS:
        if not ConfigData.is_installed(app):
          try:
            Action.register_action(app)
          except exceptions.ImproperlyConfigured:
            pass #logging.error("   can not register %s actions" % app)

        if not ConfigData.is_installed(app):
          try:
            _install = util.get_attr_from("%s.config.install" % app)
            _install()
          except exceptions.ImproperlyConfigured:
            pass #logging.error("ImproperlyConfigured -> %s.config.install" % app)

          areas = util.get_config_value(app, "areas", {})
          areas_vals = sorted(areas.values(), key=lambda x: x.get("order", 1000))
          
          ConfigData.set_configdata(app, True, label='installed_app',
                                    extra={'adminareas':areas_vals})