Exemplo n.º 1
0
  def test_permissions_for_backlog_workflow(self, mock_get_current_user):  # noqa # pylint: disable=invalid-name
    """Tests whether the creator has all the necessary permissions for
    backlog workflow."""

    my_person = Person(name="kekec", email="*****@*****.**")
    creator_role = Role.query.filter(Role.name == "Creator").one()
    user_role = UserRole(role=creator_role, person=my_person)  # noqa # pylint: disable=unused-variable
    mock_get_current_user.return_value = Person(name="Mojca",
                                                email="*****@*****.**")
    backlog_workflow = db.session\
                         .query(Workflow)\
                         .filter(Workflow.kind == "Backlog").one()
    workflow_ctx = backlog_workflow.context.id
    user_perms = load_permissions_for(my_person)

    actions = ["read", "edit", "update"]
    _types = ["Workflow", "Cycle", "CycleTaskGroup",
              "CycleTaskGroupObjectTask", "TaskGroup"]

    for action in actions:
      for obj_type in _types:
        self.assertTrue(workflow_ctx in
                        user_perms[action][obj_type]['contexts'])
    ctgot_ctxs = user_perms['delete']['CycleTaskGroupObjectTask']['contexts']
    self.assertTrue(workflow_ctx in ctgot_ctxs)
  def test_permissions_for_backlog_workflow(self, mock_get_current_user):  # noqa # pylint: disable=invalid-name
    """Tests whether the creator has all the necessary permissions for
    backlog workflow."""

    my_person = Person(name="kekec", email="*****@*****.**")
    creator_role = Role.query.filter(Role.name == "Creator").one()
    user_role = UserRole(role=creator_role, person=my_person)  # noqa # pylint: disable=unused-variable
    mock_get_current_user.return_value = Person(name="Mojca",
                                                email="*****@*****.**")
    backlog_workflow = db.session\
                         .query(Workflow)\
                         .filter(and_(Workflow.kind == "Backlog",
                                      Workflow.frequency == "one_time")).one()
    workflow_ctx = backlog_workflow.context.id
    user_perms = load_permissions_for(my_person)

    actions = ["read", "edit", "update"]
    _types = ["Workflow", "Cycle", "CycleTaskGroup",
              "CycleTaskGroupObjectTask", "TaskGroup"]

    for action in actions:
      for obj_type in _types:
        self.assertTrue(workflow_ctx in
                        user_perms[action][obj_type]['contexts'])
    ctgot_ctxs = user_perms['delete']['CycleTaskGroupObjectTask']['contexts']
    self.assertTrue(workflow_ctx in ctgot_ctxs)
    def load_perms(user_id, new_perms):
        """Emulate procedure to load permissions
    """

        with mock.patch(
                'ggrc_basic_permissions._load_permissions_from_database',
                return_value=new_perms):

            mock_user = mock.Mock()
            mock_user.id = user_id

            return ggrc_basic_permissions.load_permissions_for(mock_user)
Exemplo n.º 4
0
  def load_perms(user_id, new_perms):
    """Emulate procedure to load permissions
    """

    with mock.patch(
        'ggrc_basic_permissions._load_permissions_from_database',
        return_value=new_perms
    ):

      mock_user = mock.Mock()
      mock_user.id = user_id

      return ggrc_basic_permissions.load_permissions_for(mock_user)
Exemplo n.º 5
0
 def _recalculate_permissions_cache(self):
     """Recalculate permissions cache for user `UserRole` relates to."""
     with utils.benchmark(
             "Invalidate permissions cache for user in UserRole"):
         from ggrc_basic_permissions import load_permissions_for
         load_permissions_for(self.person, expire_old=True)