Esempio n. 1
0
    def _create_actions(self):
        # Gloabl actions avaiable at any time from all applications
        actions = [
            ('preferences', None),
            ('export', None),
            ('print', None),
            ('sign_out', None),
            ('change_password', None),
            ('HelpApp', None),
            ('HelpContents', None),
            ('HelpTranslate', None),
            ('HelpSupport', None),
            ('HelpChat', None),
            ('HelpAbout', None),
            ('quit', None),
        ]

        pm = PermissionManager.get_permission_manager()
        group = Gio.SimpleActionGroup()
        self.toplevel.insert_action_group('stoq', group)
        for (name, param_type) in actions:
            action = Gio.SimpleAction.new(name, param_type)
            group.add_action(action)
            # Save the action in self so that auto signal connections work
            setattr(self, name, action)

            # Check permissions
            key, required = self.action_permissions.get(
                name, (None, pm.PERM_ALL))
            if not pm.get(key) & required:
                action.set_enabled(False)
Esempio n. 2
0
    def _create_actions(self):
        # Gloabl actions avaiable at any time from all applications
        actions = [
            ('preferences', None),
            ('export', None),
            ('print', None),
            ('sign_out', None),
            ('change_password', None),
            ('HelpApp', None),
            ('HelpContents', None),
            ('HelpTranslate', None),
            ('HelpSupport', None),
            ('HelpChat', None),
            ('HelpAbout', None),
            ('quit', None),
        ]

        pm = PermissionManager.get_permission_manager()
        group = Gio.SimpleActionGroup()
        self.toplevel.insert_action_group('stoq', group)
        for (name, param_type) in actions:
            action = Gio.SimpleAction.new(name, param_type)
            group.add_action(action)
            # Save the action in self so that auto signal connections work
            setattr(self, name, action)

            # Check permissions
            key, required = self.action_permissions.get(name,
                                                        (None, pm.PERM_ALL))
            if not pm.get(key) & required:
                action.set_enabled(False)
Esempio n. 3
0
 def __init__(self, wizard, store, model):
     WizardEditorStep.__init__(self, store, wizard, model)
     pm = PermissionManager.get_permission_manager()
     if not pm.can_create('Supplier'):
         self.add_supplier.hide()
     if not pm.can_edit('Supplier'):
         self.edit_supplier.hide()
    def setUp(self):
        super(BaseTest, self).setUp()

        # The final interface depends on this
        pm = PermissionManager.get_permission_manager()
        pm.set('Product', PermissionManager.PERM_ALL)

        self.wizard = self.wizard_class(self.store)
        self.step = self.step_class(self.wizard, None, self.store, self.wizard.model)
Esempio n. 5
0
    def tearDownClass(cls):
        """Undo what is done in the setup on NFeUI

        We must do this otherwise it will affect other tests
        """
        pm = PermissionManager.get_permission_manager()
        pm.set('InvoiceLayout', pm.PERM_ALL)
        pm.set('InvoicePrinter', pm.PERM_ALL)
        pm.set('app.sales.print_invoice', pm.PERM_ALL)
Esempio n. 6
0
    def tearDownClass(cls):
        """Undo what is done in the setup on NFeUI

        We must do this otherwise it will affect other tests
        """
        pm = PermissionManager.get_permission_manager()
        pm.set('InvoiceLayout', pm.PERM_ALL)
        pm.set('InvoicePrinter', pm.PERM_ALL)
        pm.set('app.sales.print_invoice', pm.PERM_ALL)
Esempio n. 7
0
    def __init__(self):
        SaleStatusChangedEvent.connect(self._on_SaleStatusChanged)

        pm = PermissionManager.get_permission_manager()
        pm.set('InvoiceLayout', pm.PERM_HIDDEN)
        pm.set('InvoicePrinter', pm.PERM_HIDDEN)

        # since the nfe plugin was enabled, the user must not be able to print
        # the regular fiscal invoice (replaced by the nfe).
        pm.set('app.sales.print_invoice', pm.PERM_HIDDEN)
Esempio n. 8
0
    def __init__(self):
        SaleStatusChangedEvent.connect(self._on_SaleStatusChanged)

        pm = PermissionManager.get_permission_manager()
        pm.set('InvoiceLayout', pm.PERM_HIDDEN)
        pm.set('InvoicePrinter', pm.PERM_HIDDEN)

        # since the nfe plugin was enabled, the user must not be able to print
        # the regular fiscal invoice (replaced by the nfe).
        pm.set('app.sales.print_invoice', pm.PERM_HIDDEN)
Esempio n. 9
0
    def setUp(self):
        super(BaseTest, self).setUp()

        # The final interface depends on this
        pm = PermissionManager.get_permission_manager()
        pm.set('Product', PermissionManager.PERM_ALL)

        self.wizard = self.wizard_class(self.store)
        self.step = self.step_class(self.wizard, None, self.store,
                                    self.wizard.model)
Esempio n. 10
0
 def __init__(self, store, model=None, visual_mode=False, category=None):
     self._default_category = category
     self.proxy = None
     super(WorkOrderEditor, self).__init__(store, model=model,
                                           visual_mode=visual_mode)
     self._setup_widgets()
     pm = PermissionManager.get_permission_manager()
     if not pm.can_create('WorkOrderCategory'):
         self.category_create.hide()
     if not pm.can_edit('WorkOrderCategory'):
         self.category_edit.hide()
Esempio n. 11
0
    def __init__(self):
        self._setup_params()
        self._setup_events()

        pm = PermissionManager.get_permission_manager()
        pm.set('InvoiceLayout', pm.PERM_HIDDEN)
        pm.set('InvoicePrinter', pm.PERM_HIDDEN)

        # since the nfe plugin was enabled, the user must not be able to print
        # the regular fiscal invoice (replaced by the nfe).
        pm.set('app.sales.print_invoice', pm.PERM_HIDDEN)
        self._update_forms()
Esempio n. 12
0
    def __init__(self):
        self._setup_params()
        self._setup_events()

        pm = PermissionManager.get_permission_manager()
        pm.set('InvoiceLayout', pm.PERM_HIDDEN)
        pm.set('InvoicePrinter', pm.PERM_HIDDEN)

        # since the nfe plugin was enabled, the user must not be able to print
        # the regular fiscal invoice (replaced by the nfe).
        pm.set('app.sales.print_invoice', pm.PERM_HIDDEN)
        self._update_forms()
Esempio n. 13
0
    def _setup_permission(self):
        if not self.editor_class:
            return

        pm = PermissionManager.get_permission_manager()
        key = self.editor_class.model_type.__name__

        if not pm.can_create(key):
            self.listcontainer.set_list_type(ListType.READONLY)
        elif not pm.can_edit(key) or not pm.can_delete(key):
            self.listcontainer.set_list_type(ListType.ADDONLY)
        else:
            self.listcontainer.set_list_type(ListType.NORMAL)
Esempio n. 14
0
    def _setup_permission(self):
        if not self.editor_class:
            return

        pm = PermissionManager.get_permission_manager()
        key = self.editor_class.model_type.__name__

        if not pm.can_create(key):
            self.listcontainer.set_list_type(ListType.READONLY)
        elif not pm.can_edit(key) or not pm.can_delete(key):
            self.listcontainer.set_list_type(ListType.ADDONLY)
        else:
            self.listcontainer.set_list_type(ListType.NORMAL)
Esempio n. 15
0
    def __init__(self):
        SaleReturnWizardFinishEvent.connect(self._on_SaleReturnWizardFinish)
        SaleStatusChangedEvent.connect(self._on_SaleStatusChanged)
        StockDecreaseWizardFinishEvent.connect(self._on_StockDecreaseWizardFinish)
        StockTransferWizardFinishEvent.connect(self._on_StockTransferWizardFinish)
        # TODO: Before enable the the NF-e generation. Save the invoice data,
        # in Invoice table (for each operation below).
#        NewLoanWizardFinishEvent.connect(self._on_NewLoanWizardFinish)

        pm = PermissionManager.get_permission_manager()
        pm.set('InvoiceLayout', pm.PERM_HIDDEN)
        pm.set('InvoicePrinter', pm.PERM_HIDDEN)

        # since the nfe plugin was enabled, the user must not be able to print
        # the regular fiscal invoice (replaced by the nfe).
        pm.set('app.sales.print_invoice', pm.PERM_HIDDEN)
        self._update_forms()
Esempio n. 16
0
    def add_ui_actions(self,
                       ui_string,
                       actions,
                       name='Actions',
                       action_type='normal',
                       filename=None,
                       instance=None):
        if instance is None:
            instance = self
        ag = self._get_action_group(name)

        to_add = [entry[0] for entry in actions]
        for action in ag.list_actions():
            if action.get_name() in to_add:
                ag.remove_action(action)

        if action_type == 'normal':
            ag.add_actions(actions)
        elif action_type == 'toggle':
            ag.add_toggle_actions(actions)
        elif action_type == 'radio':
            ag.add_radio_actions(actions)
        else:
            raise ValueError(action_type)
        if filename is not None:
            ui_string = environ.get_resource_string('stoq', 'uixml', filename)
            ui_string = ui_string.decode()
        ui_id = self.uimanager.add_ui_from_string(ui_string)

        self.action_permissions.update(self.common_action_permissions)
        pm = PermissionManager.get_permission_manager()
        for action in ag.list_actions():
            action_name = action.get_name()
            setattr(instance, action_name, action)

            # Check permissions
            key, required = instance.action_permissions.get(
                action_name, (None, pm.PERM_ALL))
            if not pm.get(key) & required:
                action.set_visible(False)
                # Disable keyboard shortcut
                path = action.get_accel_path()
                Gtk.AccelMap.change_entry(path, 0, 0, True)

        return ui_id
Esempio n. 17
0
    def test_show_without_permission(self, run_dialog):
        # Our only permission now is to see details
        pm = PermissionManager.get_permission_manager()
        pm.set('Product', pm.PERM_ONLY_DETAILS)
        search = self._show_search()

        # New button shoud not be visible and edit button should actually be
        # 'Details'
        self.assertNotVisible(search._toolbar, ['new_button'])
        self.assertSensitive(search._toolbar, ['edit_button'])
        self.assertEquals(search._toolbar.edit_button_label.get_label(),
                          _('Details'))

        # Editor should be called with visual mode set.
        self.click(search._toolbar.edit_button)
        args, kwargs = run_dialog.call_args
        self.assertTrue('visual_mode' in kwargs)
        self.assertEquals(kwargs['visual_mode'], True)
Esempio n. 18
0
    def testShowWithoutPermission(self, run_dialog):
        # Our only permission now is to see details
        pm = PermissionManager.get_permission_manager()
        pm.set('Product', pm.PERM_ONLY_DETAILS)
        search = self._show_search()

        # New button shoud not be visible and edit button should actually be
        # 'Details'
        self.assertNotVisible(search._toolbar, ['new_button'])
        self.assertSensitive(search._toolbar, ['edit_button'])
        self.assertEquals(search._toolbar.edit_button_label.get_label(),
                          _('Details'))

        # Editor should be called with visual mode set.
        self.click(search._toolbar.edit_button)
        args, kwargs = run_dialog.call_args
        self.assertTrue('visual_mode' in kwargs)
        self.assertEquals(kwargs['visual_mode'], True)
Esempio n. 19
0
 def __init__(self, store, model=None, visual_mode=False, category=None,
              available_categories=None):
     """
     @param category: The default category that should be already selected.
     @param available_categories: A list of categories names that should be
       available to the user. If None, all categoires will be available
     """
     self._default_category = category
     self.categories_for_combo = available_categories
     self.proxy = None
     super(WorkOrderEditor, self).__init__(store, model=model,
                                           visual_mode=visual_mode)
     self._setup_widgets()
     pm = PermissionManager.get_permission_manager()
     if not pm.can_create('WorkOrderCategory'):
         self.category_create.hide()
     if not pm.can_edit('WorkOrderCategory'):
         self.category_edit.hide()
Esempio n. 20
0
    def _check_permissions(self):
        if not self.editor_class:
            return

        pm = PermissionManager.get_permission_manager()
        key = self.editor_class.model_type.__name__
        if not pm.can_create(key):
            self.hide_new_button()

        if not pm.can_edit(key):
            if pm.can_see_details(key):
                # Replace edit button with a details button. self._read_only
                # will activate visual_mode for the editor
                self._read_only = True
                self._toolbar.edit_button_label.set_text(_('Details'))
                self._toolbar.edit_button_image.set_from_stock('gtk-info', gtk.ICON_SIZE_BUTTON)
            else:
                self.hide_edit_button()
Esempio n. 21
0
 def __init__(self, store, model=None, visual_mode=False, category=None,
              available_categories=None):
     """
     @param category: The default category that should be already selected.
     @param available_categories: A list of categories names that should be
       available to the user. If None, all categoires will be available
     """
     self._default_category = category
     self.categories_for_combo = available_categories
     self.proxy = None
     super(WorkOrderEditor, self).__init__(store, model=model,
                                           visual_mode=visual_mode)
     self._setup_widgets()
     pm = PermissionManager.get_permission_manager()
     if not pm.can_create('WorkOrderCategory'):
         self.category_create.hide()
     if not pm.can_edit('WorkOrderCategory'):
         self.category_edit.hide()
Esempio n. 22
0
    def __init__(self):
        SaleReturnWizardFinishEvent.connect(self._on_SaleReturnWizardFinish)
        SaleStatusChangedEvent.connect(self._on_SaleStatusChanged)
        StockDecreaseWizardFinishEvent.connect(
            self._on_StockDecreaseWizardFinish)
        StockTransferWizardFinishEvent.connect(
            self._on_StockTransferWizardFinish)
        # TODO: Before enable the the NF-e generation. Save the invoice data,
        # in Invoice table (for each operation below).
        #        NewLoanWizardFinishEvent.connect(self._on_NewLoanWizardFinish)

        pm = PermissionManager.get_permission_manager()
        pm.set('InvoiceLayout', pm.PERM_HIDDEN)
        pm.set('InvoicePrinter', pm.PERM_HIDDEN)

        # since the nfe plugin was enabled, the user must not be able to print
        # the regular fiscal invoice (replaced by the nfe).
        pm.set('app.sales.print_invoice', pm.PERM_HIDDEN)
        self._update_forms()
Esempio n. 23
0
    def add_ui_actions(self, ui_string,
                       actions,
                       name='Actions',
                       action_type='normal',
                       filename=None,
                       instance=None):
        if instance is None:
            instance = self
        ag = self._get_action_group(name)

        to_add = [entry[0] for entry in actions]
        for action in ag.list_actions():
            if action.get_name() in to_add:
                ag.remove_action(action)

        if action_type == 'normal':
            ag.add_actions(actions)
        elif action_type == 'toggle':
            ag.add_toggle_actions(actions)
        elif action_type == 'radio':
            ag.add_radio_actions(actions)
        else:
            raise ValueError(action_type)
        if filename is not None:
            ui_string = environ.get_resource_string('stoq', 'uixml', filename)
        ui_id = self.uimanager.add_ui_from_string(ui_string)

        self.action_permissions.update(self.common_action_permissions)
        pm = PermissionManager.get_permission_manager()
        for action in ag.list_actions():
            action_name = action.get_name()
            setattr(instance, action_name, action)

            # Check permissions
            key, required = instance.action_permissions.get(action_name,
                                                            (None, pm.PERM_ALL))
            if not pm.get(key) & required:
                action.set_visible(False)
                # Disable keyboard shortcut
                path = action.get_accel_path()
                gtk.accel_map_change_entry(path, 0, 0, True)

        return ui_id
Esempio n. 24
0
    def tearDown(self):
        GUITest.tearDown(self)

        # Reset the permitions so they wont influence other tests
        pm = PermissionManager.get_permission_manager()
        pm.set('Product', PermissionManager.PERM_ALL)
Esempio n. 25
0
    def tearDown(self):
        GUITest.tearDown(self)

        # Reset the permitions so they wont influence other tests
        pm = PermissionManager.get_permission_manager()
        pm.set('Product', PermissionManager.PERM_ALL)