blob: 018aaf3674ee0543e82cb528b417244d0d182dbd [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# Copyright 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style
3# license that can be found in the LICENSE file or at
4# https://developers.google.com/open-source/licenses/bsd
5
6"""A class to display the project summary page."""
7from __future__ import print_function
8from __future__ import division
9from __future__ import absolute_import
10
11import logging
12
13from businesslogic import work_env
14from framework import permissions
15from framework import servlet
16from project import project_helpers
17from project import project_views
18
Copybara854996b2021-09-07 19:36:02 +000019
20class ProjectSummary(servlet.Servlet):
21 """Page to show brief project description and process documentation."""
22
23 _PAGE_TEMPLATE = 'project/project-summary-page.ezt'
24 _MAIN_TAB_MODE = servlet.Servlet.MAIN_TAB_PROCESS
25
26 def GatherPageData(self, mr):
27 """Build up a dictionary of data values to use when rendering the page."""
28
29 with mr.profiler.Phase('getting project star count'):
30 num_stars = self.services.project_star.CountItemStars(
31 mr.cnxn, mr.project_id)
32 plural = '' if num_stars == 1 else 's'
33
34 page_data = {
35 'admin_tab_mode': self.PROCESS_TAB_SUMMARY,
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020036 'formatted_project_description': mr.project.description,
Copybara854996b2021-09-07 19:36:02 +000037 'access_level': project_views.ProjectAccessView(mr.project.access),
38 'num_stars': num_stars,
39 'plural': plural,
40 'home_page': mr.project.home_page,
41 'docs_url': mr.project.docs_url,
42 'source_url': mr.project.source_url,
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020043 }
Copybara854996b2021-09-07 19:36:02 +000044
45 return page_data
46
47 def GatherHelpData(self, mr, page_data):
48 """Return a dict of values to drive on-page user help.
49
50 Args:
51 mr: common information parsed from the HTTP request.
52 page_data: Dictionary of base and page template data.
53
54 Returns:
55 A dict of values to drive on-page user help, to be added to page_data.
56 """
57 help_data = super(ProjectSummary, self).GatherHelpData(mr, page_data)
58 with work_env.WorkEnv(mr, self.services) as we:
59 userprefs = we.GetUserPrefs(mr.auth.user_id)
60 dismissed = [
61 pv.name for pv in userprefs.prefs if pv.value == 'true']
62 project = mr.project
63
64 # Cue cards for project owners.
65 if self.CheckPerm(mr, permissions.EDIT_PROJECT):
66 if ('document_team_duties' not in dismissed and
67 len(project_helpers.AllProjectMembers(project)) > 1 and
68 not self.services.project.GetProjectCommitments(
69 mr.cnxn, mr.project_id).commitments):
70 help_data['cue'] = 'document_team_duties'
71
72 return help_data