Esempio n. 1
0
    def setUp(self):
        super(GroupsAPITest, self).setUp()
        self.testapp = webtest.TestApp(gae_main.app)

        self.testbed = testbed.Testbed()

        self.testbed.activate()
        self.testbed.setup_env(overwrite=True,
                               USER_EMAIL='*****@*****.**',
                               USER_ID='123',
                               USER_IS_ADMIN='0',
                               DEFAULT_VERSION_HOSTNAME='example.appspot.com')

        self.testbed.init_all_stubs()

        self.headers = {'X-Simian-API-Info-Key': groups.API_INFO_KEY}
        models.Group(key_name='test group', users=['user1', 'user4']).put()
        models.Group(key_name='test group2', users=['user1', 'user2']).put()
Esempio n. 2
0
    def post(self):
        """Create a new group, or overwrites an existing group's membership list."""
        self._DoAuth()
        self._CheckApiKey()

        group = self.request.get('group')
        members = list(set(self.request.get('members').split(',')))

        new_group = models.Group(key_name=group, users=members)
        new_group.put()
Esempio n. 3
0
  def post(self):
    """POST handler."""
    if not self.IsAdminUser():
      self.error(httplib.FORBIDDEN)
      return

    group_name = urllib.unquote(self.request.get('group').strip())
    action = self.request.get('action')
    if action == 'create':
      group = models.Group(key_name=group_name)
      users = self.request.get_all('user')
      if users:
        group.users = users
      group.put()
      msg = 'Group successfully saved.'
    elif action == 'delete':
      group_manifest_mods = models.GroupManifestModification.all().filter(
          'group_key_name =', group_name).get()
      if group_manifest_mods:
        msg = "Group not deleted as it's being used for Manifest Modifications."
      else:
        group = models.Group.get_by_key_name(group_name)
        if group:
          group.delete()
        else:
          self.error(httplib.NOT_FOUND)
          return
        msg = 'Group successfully deleted.'
    elif action == 'change':
      users = self.request.get_all('user')
      add_group = self.request.get('add') == '1'
      group = models.Group.get_by_key_name(group_name)
      if not group:
        self.error(httplib.NOT_FOUND)
        return

      if add_group:
        group.users += users
      else:
        group.users = [u for u in group.users if u not in users]
      group.put()
      msg = 'Group successfully modified.'

    self.redirect('/admin/groups?msg=%s' % msg)
Esempio n. 4
0
  def setUp(self):
    super(AdminGroupsTest, self).setUp()
    self.testapp = webtest.TestApp(gae_main.app)

    models.Group(key_name='test group', users=['user1', 'user4']).put()
    models.Group(key_name='test group2', users=['user1', 'user2']).put()