예제 #1
0
 def GetDomainAdmin(self, user, domain):  # pylint:disable=unused-argument
     """Displays the administration page for the given domain."""
     domain_name = domain
     perms.AssertAccess(perms.Role.DOMAIN_ADMIN, domain_name)
     domain = domains.Domain.Get(domain_name)
     if not domain:
         raise base_handler.Error(404, 'Unknown domain %r.' % domain_name)
     subject_roles = perms.GetSubjectsForTarget(domain_name)
     user_roles = [(users.Get(subj), _MaxRole(r))
                   for (subj, r) in subject_roles.items()
                   if perms.IsUserId(subj)]
     user_roles.sort(key=lambda (u, r): u.email)
     labels = sorted(e.label
                     for e in model.CatalogEntry.GetAll(domain_name))
     self.response.out.write(
         self.RenderTemplate(
             'admin_domain.html', {
                 'domain': domain,
                 'user_roles': user_roles,
                 'labels': labels,
                 'domain_role': _MaxRole(
                     subject_roles.get(domain_name, set())),
                 'user_permission_choices': DOMAIN_PERMISSION_CHOICES,
                 'initial_domain_role_choices': INITIAL_DOMAIN_ROLE_CHOICES,
                 'show_welcome': self.request.get('welcome', '')
             }))
예제 #2
0
 def Put(cls,
         name,
         default_label=None,
         has_sticky_catalog_entries=None,
         initial_domain_role=None,
         user=None):
     """Creates and stores a Domain object, overwriting any existing one."""
     name = NormalizeDomainName(name)
     domain_model = _DomainModel.get_by_id(name)
     if domain_model:  # modify an existing entity (DOMAIN_ADMIN is required)
         perms.AssertAccess(perms.Role.DOMAIN_ADMIN, name, user)
         if default_label is not None:
             domain_model.default_label = default_label
         if has_sticky_catalog_entries is not None:
             domain_model.has_sticky_catalog_entries = has_sticky_catalog_entries
         if initial_domain_role is not None:
             domain_model.initial_domain_role = initial_domain_role
         domain_model.put()
     else:  # create a new entity (no permissions are required)
         if default_label is None:
             default_label = 'empty'
         if initial_domain_role is None:
             initial_domain_role = perms.Role.MAP_VIEWER
         domain_model = _DomainModel(
             id=name,
             default_label=default_label,
             has_sticky_catalog_entries=bool(has_sticky_catalog_entries),
             initial_domain_role=initial_domain_role)
         domain_model.put()
         logs.RecordEvent(logs.Event.DOMAIN_CREATED,
                          domain_name=name,
                          uid=user.id if user else None)
     domain = cls.FromModel(domain_model)
     CACHE.Set(AddDomainNamePrefixForCache(name), domain)
     return domain
예제 #3
0
 def Get(self, map_id):
     """Renders the admin page."""
     perms.AssertAccess(perms.Role.ADMIN)
     map_object = model.Map.Get(map_id) or model.Map.GetDeleted(map_id)
     if not map_object:
         raise base_handler.Error(404, 'Map %r not found.' % map_id)
     self.response.out.write(
         self.RenderTemplate('admin_map.html', {'map': map_object}))
예제 #4
0
 def Post(self, map_id):
     """Handles a POST (block/unblock, delete/undelete, or wipe)."""
     perms.AssertAccess(perms.Role.ADMIN)
     map_object = model.Map.Get(map_id) or model.Map.GetDeleted(map_id)
     if not map_object:
         raise base_handler.Error(404, 'Map %r not found.' % map_id)
     if self.request.get('block'):
         map_object.SetBlocked(True)
     if self.request.get('unblock'):
         map_object.SetBlocked(False)
     if self.request.get('delete'):
         map_object.Delete()
     if self.request.get('undelete'):
         map_object.Undelete()
     if self.request.get('wipe'):
         map_object.Wipe()
     self.redirect(map_id)
예제 #5
0
 def Post(self, user, domain):
     """Landing for posts from the domain administration page."""
     which = self.request.POST.pop('form')
     target = self.request.path
     if which != 'create-domain':
         perms.AssertAccess(perms.Role.DOMAIN_ADMIN, domain, user)
         if not domains.Domain.Get(domain):
             raise base_handler.Error(404, 'Unknown domain %r.' % domain)
     if which == 'domain-settings':
         self.UpdateDomainSettings(self.request.POST, domain)
     elif which == 'create-domain':
         self.CreateDomain(domain, user)
         target += '?welcome=1'
     else:  # user or domain permissions
         inputs = dict(self.request.POST)
         self.AddNewUserIfPresent(inputs, domain)
         # Set access to this domain for all users with this e-mail domain.
         self.UpdateDomainRole(inputs, domain)
         # Set access to this domain for individually specified users.
         SetRolesForDomain(self.FindNewPerms(inputs), domain)
     self.redirect(target)
예제 #6
0
  def RenderReviewPage(self, map_object):
    """Renders the map review page.

    Args:
      map_object: The model.Map instance being reviewed.
    """
    perms.AssertAccess(perms.Role.MAP_REVIEWER, map_object)

    self.count = int(self.request.get('count') or 50)
    self.skip = int(self.request.get('skip') or 0)
    self.reviewed = _NoneIfTrueElseFalse(self.request.get('reviewed'))
    self.hidden = _NoneIfFalseElseTrue(self.request.get('hidden'))
    self.report_id = self.request.get('id', '').strip()
    self.query = self.request.get('query', '').strip()
    self.author = self.request.get('author', '').strip() or None
    self.topic_id = self.request.get('topic')

    prev_skip = max(0, self.skip - self.count)
    prev_url = self._GetUrl(skip=prev_skip) if self.skip else None
    next_skip = 0
    next_url = None

    map_id = map_object.key.name()
    map_root = map_object.map_root

    topic_ids = []
    report_dicts = []

    if 'topics' in map_root:
      topic_ids, report_dicts = self._ExtractTopicsAndReports(map_id, map_root)

    if len(report_dicts) > self.count:
      report_dicts = report_dicts[:self.count]
      next_skip = self.skip + self.count
      next_url = self._GetUrl(skip=next_skip)

    self._RenderTemplate(map_object, report_dicts, topic_ids,
                         prev_url, next_url, next_skip)
예제 #7
0
  def HandlePost(self, map_object):
    """Handles a POST.

    Possible user actions are marking the set of input reports reviewed,
    upvoted or downvoted.

    Upon success, the user is redirected to the review page.

    Args:
      map_object: The model.Map instance being reviewed.
    """
    perms.AssertAccess(perms.Role.MAP_REVIEWER, map_object)

    to_accept = self.request.get_all('accept')
    to_downvote = self.request.get_all('downvote')
    to_upvote = self.request.get_all('upvote')

    model.CrowdReport.MarkAsReviewed(to_accept + to_downvote + to_upvote)
    for report_id in to_downvote:
      model.CrowdVote.Put(report_id, self.GetCurrentUserUrl(), 'REVIEWER_DOWN')
    for report_id in to_upvote:
      model.CrowdVote.Put(report_id, self.GetCurrentUserUrl(), 'REVIEWER_UP')

    self.redirect(self._GetUrl())
예제 #8
0
 def GetGeneralAdmin(self):
     """Renders the general admin page."""
     perms.AssertAccess(perms.Role.ADMIN)
     self.response.out.write(self.RenderTemplate('admin.html', {}))