예제 #1
0
def isNoRoleEligibleForOrg(profile, org_key):
    """Tells whether the specified user is eligible to have no role for the
  specified organization.

  A user is eligible for no role if he or she does not have any obligations
  to the organization.

  Please note that this function executes a non-ancestor query, so it cannot
  be safely used within transactions.

  Args:
    profile: profile entity.
    org_key: organization key.

  Returns:
    RichBool whose value is set to True, if the user is eligible for no
    role for the specified organization. Otherwise, RichBool whose value is set
    to False and extra part is a string that represents a reason why the user
    is not eligible to resign from role at this time.
  """
    if org_key in profile.admin_for:
        result = profile_logic.canResignAsOrgAdminForOrg(profile, org_key)
        if not result:
            return result

    if org_key in profile.mentor_for:
        result = canResignAsMentorForOrg(profile, org_key)
        if not result:
            return result

    return rich_bool.TRUE
예제 #2
0
def isNoRoleEligibleForOrg(profile, org_key):
  """Tells whether the specified user is eligible to have no role for the
  specified organization.

  A user is eligible for no role if he or she does not have any obligations
  to the organization.

  Please note that this function executes a non-ancestor query, so it cannot
  be safely used within transactions.

  Args:
    profile: profile entity.
    org_key: organization key.

  Returns:
    RichBool whose value is set to True, if the user is eligible for no
    role for the specified organization. Otherwise, RichBool whose value is set
    to False and extra part is a string that represents a reason why the user
    is not eligible to resign from role at this time.
  """
  if org_key in profile.admin_for:
    result = profile_logic.canResignAsOrgAdminForOrg(profile, org_key)
    if not result:
      return result

  if org_key in profile.mentor_for:
    result = canResignAsMentorForOrg(profile, org_key)
    if not result:
      return result

  return rich_bool.TRUE
예제 #3
0
  def testMoreOrgAdmins(self):
    """Tests that org admin can resign if there is another one."""
    # seed another org admin
    profile_utils.seedNDBProfile(
        self.program.key(), admin_for=[self.organization_one.key])

    # now the org admin can resign, as there is another admin
    can_resign = profile_logic.canResignAsOrgAdminForOrg(
        self.org_admin, self.organization_one.key)
    self.assertTrue(can_resign)
예제 #4
0
def canResignAsOrgAdminForOrg(profile, org_key):
  """Tells whether the specified profile can resign from their organization
  administrator role for the specified organization.

  An organization administrator may be removed from the list of administrators
  of an organization, if there is at least one other user with this role.

  Args:
    profile: the specified profile entity.
    org_key: the specified organization entity.

  Returns:
    RichBool whose value is set to True, if the organization administrator
    is allowed to resign. Otherwise, RichBool whose value is set to False
    and extra part is a string that represents the reason why the user
    is not allowed to resign.
  """
  return profile_logic.canResignAsOrgAdminForOrg(
      profile, org_key, models=types.SOC_MODELS)
예제 #5
0
def canResignAsOrgAdminForOrg(profile, org_key):
    """Tells whether the specified profile can resign from their organization
  administrator role for the specified organization.

  An organization administrator may be removed from the list of administrators
  of an organization, if there is at least one other user with this role.

  Args:
    profile: the specified profile entity.
    org_key: the specified organization entity.

  Returns:
    RichBool whose value is set to True, if the organization administrator
    is allowed to resign. Otherwise, RichBool whose value is set to False
    and extra part is a string that represents the reason why the user
    is not allowed to resign.
  """
    return profile_logic.canResignAsOrgAdminForOrg(profile,
                                                   org_key,
                                                   models=types.SOC_MODELS)
예제 #6
0
 def testNotOrgAdminForOrg(self):
   """Tests that error is raised if the profile is not an org admin."""
   with self.assertRaises(ValueError):
     profile_logic.canResignAsOrgAdminForOrg(
         self.org_admin, self.organization_two.key)
예제 #7
0
 def testOnlyOrgAdmin(self):
   """Tests that the only org admin cannot resign."""
   can_resign = profile_logic.canResignAsOrgAdminForOrg(
       self.org_admin, self.organization_one.key)
   self.assertFalse(can_resign)
   self.assertEqual(can_resign.extra, profile_logic.ONLY_ORG_ADMIN)