Exemple #1
0
  def ProcessFormData(self, mr, post_data):
    """Validate and store the contents of the issues tracker admin page.

    Args:
      mr: commonly used info parsed from the request.
      post_data: HTML form data from the request.

    Returns:
      String URL to redirect the user to, or None if response was already sent.
    """
    config, component_def = self._GetComponentDef(mr)
    allow_edit = permissions.CanEditComponentDef(
        mr.auth.effective_ids, mr.perms, mr.project, component_def, config)
    if not allow_edit:
      raise permissions.PermissionException(
          'User is not allowed to edit or delete this component')

    if 'deletecomponent' in post_data:
      allow_delete = not tracker_bizobj.FindDescendantComponents(
          config, component_def)
      if not allow_delete:
        raise permissions.PermissionException(
            'User tried to delete component that had subcomponents')
      return self._ProcessDeleteComponent(mr, component_def)

    else:
      return self._ProcessEditComponent(mr, post_data, config, component_def)
Exemple #2
0
  def components_delete(self, request):
    """Delete a component."""
    mar = self.mar_factory(request)
    config = self._services.config.GetProjectConfig(mar.cnxn, mar.project_id)
    component_path = request.componentPath
    component_def = tracker_bizobj.FindComponentDef(
        component_path, config)
    if not component_def:
      raise config_svc.NoSuchComponentException(
          'The component %s does not exist.' % component_path)
    if not permissions.CanViewComponentDef(
        mar.auth.effective_ids, mar.perms, mar.project, component_def):
      raise permissions.PermissionException(
          'User is not allowed to view this component %s' % component_path)
    if not permissions.CanEditComponentDef(
        mar.auth.effective_ids, mar.perms, mar.project, component_def, config):
      raise permissions.PermissionException(
          'User is not allowed to delete this component %s' % component_path)

    allow_delete = not tracker_bizobj.FindDescendantComponents(
        config, component_def)
    if not allow_delete:
      raise permissions.PermissionException(
          'User tried to delete component that had subcomponents')

    self._services.issue.DeleteComponentReferences(
        mar.cnxn, component_def.component_id)
    self._services.config.DeleteComponentDef(
        mar.cnxn, mar.project_id, component_def.component_id)
    return message_types.VoidMessage()
 def testFindDescendantComponents_SomeMatch(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   cd = tracker_pb2.ComponentDef(component_id=1, path='UI')
   config.component_defs.append(cd)
   cd2 = tracker_pb2.ComponentDef(component_id=2, path='UI>Splash')
   config.component_defs.append(cd2)
   actual = tracker_bizobj.FindDescendantComponents(config, cd)
   self.assertEqual([cd2], actual)
    def GatherPageData(self, mr):
        """Build up a dictionary of data values to use when rendering the page.

    Args:
      mr: commonly used info parsed from the request.

    Returns:
      Dict of values used by EZT for rendering the page.
    """
        config, component_def = self._GetComponentDef(mr)
        users_by_id = framework_views.MakeAllUserViews(mr.cnxn,
                                                       self.services.user,
                                                       component_def.admin_ids,
                                                       component_def.cc_ids)
        component_def_view = tracker_views.ComponentDefView(
            mr.cnxn, self.services, component_def, users_by_id)
        initial_admins = [
            users_by_id[uid].email for uid in component_def.admin_ids
        ]
        initial_cc = [users_by_id[uid].email for uid in component_def.cc_ids]
        initial_labels = [
            self.services.config.LookupLabel(mr.cnxn, mr.project_id, label_id)
            for label_id in component_def.label_ids
        ]

        creator, created = self._GetUserViewAndFormattedTime(
            mr, component_def.creator_id, component_def.created)
        modifier, modified = self._GetUserViewAndFormattedTime(
            mr, component_def.modifier_id, component_def.modified)

        allow_edit = permissions.CanEditComponentDef(mr.auth.effective_ids,
                                                     mr.perms, mr.project,
                                                     component_def, config)

        subcomponents = tracker_bizobj.FindDescendantComponents(
            config, component_def)
        templates = self.services.config.TemplatesWithComponent(
            mr.cnxn, component_def.component_id, config)
        allow_delete = allow_edit and not subcomponents and not templates

        return {
            'admin_tab_mode': servlet.Servlet.PROCESS_TAB_COMPONENTS,
            'component_def': component_def_view,
            'initial_leaf_name': component_def_view.leaf_name,
            'initial_docstring': component_def.docstring,
            'initial_deprecated': ezt.boolean(component_def.deprecated),
            'initial_admins': initial_admins,
            'initial_cc': initial_cc,
            'initial_labels': initial_labels,
            'allow_edit': ezt.boolean(allow_edit),
            'allow_delete': ezt.boolean(allow_delete),
            'subcomponents': subcomponents,
            'templates': templates,
            'creator': creator,
            'created': created,
            'modifier': modifier,
            'modified': modified,
        }
Exemple #5
0
    def ProcessFormData(self, mr, post_data):
        """Processes a POST command to delete components.

    Args:
      mr: commonly used info parsed from the request.
      post_data: HTML form data from the request.

    Returns:
      String URL to redirect the user to, or None if response was already sent.
    """
        config = self.services.config.GetProjectConfig(mr.cnxn, mr.project_id)
        component_defs = self._GetComponentDefs(mr, post_data, config)
        # Reverse the component_defs so that we start deleting from subcomponents.
        component_defs.reverse()

        # Collect errors.
        perm_errors = []
        subcomponents_errors = []
        templates_errors = []
        # Collect successes.
        deleted_components = []

        for component_def in component_defs:
            allow_edit = permissions.CanEditComponentDef(
                mr.auth.effective_ids, mr.perms, mr.project, component_def,
                config)
            if not allow_edit:
                perm_errors.append(component_def.path)

            subcomponents = tracker_bizobj.FindDescendantComponents(
                config, component_def)
            if subcomponents:
                subcomponents_errors.append(component_def.path)

            templates = self.services.template.TemplatesWithComponent(
                mr.cnxn, component_def.component_id)
            if templates:
                templates_errors.append(component_def.path)

            allow_delete = allow_edit and not subcomponents and not templates
            if allow_delete:
                self._ProcessDeleteComponent(mr, component_def)
                deleted_components.append(component_def.path)
                # Refresh project config after the component deletion.
                config = self.services.config.GetProjectConfig(
                    mr.cnxn, mr.project_id)

        return framework_helpers.FormatAbsoluteURL(
            mr,
            urls.ADMIN_COMPONENTS,
            ts=int(time.time()),
            failed_perm=','.join(perm_errors),
            failed_subcomp=','.join(subcomponents_errors),
            failed_templ=','.join(templates_errors),
            deleted=','.join(deleted_components))
 def testFindDescendantComponents_Empty(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   cd = tracker_pb2.ComponentDef(component_id=1, path='UI')
   actual = tracker_bizobj.FindDescendantComponents(config, cd)
   self.assertEqual([], actual)