Ejemplo n.º 1
0
def reset_password_g_suite_account(ow4_user):
    if not ow4_user.online_mail:
        raise ValueError(
            "Det finnes ingen G Suite konto for denne epostadressen.")

    directory = setup_g_suite_client()

    password = create_temporary_password()

    user_key = get_user_key(settings.OW4_GSUITE_SETTINGS.get("DOMAIN"),
                            ow4_user.online_mail)

    logger.debug("Resetting G Suite password for {}.".format(ow4_user))

    resp = (directory.users().update(
        body={
            "password": password,
            "changePasswordAtNextLogin": True
        },
        userKey=user_key,
    ).execute())

    logger.debug("Reset G Suite password for {}, resp: {}".format(
        ow4_user, resp))

    notify_g_suite_user_account(ow4_user, password)
Ejemplo n.º 2
0
 def test_get_user_key_same_if_email(self):
     email = f"{self.user}@{self.domain}"
     self.assertEqual(email, get_user_key(self.domain, email))
Ejemplo n.º 3
0
 def test_get_user_key(self):
     expected = f"{self.user}@{self.domain}"
     self.assertEqual(expected, get_user_key(self.domain, self.user))
Ejemplo n.º 4
0
 def test_get_user_key_no_params(self):
     self.assertRaises(ValueError, lambda: get_user_key("", ""))
     self.assertRaises(ValueError, lambda: get_user_key(self.domain, ""))
     self.assertRaises(ValueError, lambda: get_user_key("", self.user))
Ejemplo n.º 5
0
 def test_get_user_key_same_if_email(self):
     email = "{user}@{domain}".format(domain=self.domain, user=self.user)
     self.assertEqual(email, get_user_key(self.domain, email))
Ejemplo n.º 6
0
 def test_get_user_key(self):
     expected = "{user}@{domain}".format(domain=self.domain, user=self.user)
     self.assertEqual(expected, get_user_key(self.domain, self.user))