Example #1
0
    def add(self, user_id, departure_date=None):
        """Adds a user to the Departing Employees list.
        `REST Documentation <https://developer.code42.com/api/#operation/DepartingEmployeeControllerV2_AddEmployee>`__

        Raises a :class:`Py42UserAlreadyAddedError` when a user already exists in the Departing Employee \
            detection list.

        Args:
            user_id (str or int): The Code42 userUid of the user you want to add to the departing \
                employees list.
            departure_date (str or datetime, optional): Date in yyyy-MM-dd format or instance of datetime.
                Date is treated as UTC. Defaults to None.

        Returns:
            :class:`py42.response.Py42Response`
        """
        if isinstance(departure_date, datetime):
            departure_date = departure_date.strftime(_DATE_FORMAT)
        tenant_id = self._user_context.get_current_tenant_id()
        data = {
            "tenantId": tenant_id,
            "userId": user_id,
            "departureDate": departure_date,
        }
        uri = self._uri_prefix.format("add")
        try:
            return self._connection.post(uri, json=data)
        except Py42BadRequestError as err:
            handle_user_already_added_error(err, user_id,
                                            "departing-employee list")
            raise
Example #2
0
    def add(self, user_id, departure_date=None):
        """Adds a user to the Departing Employees list. Creates a detection list user profile if one \
            didn't already exist.
        `REST Documentation <https://ecm-east.us.code42.com/svc/swagger/index.html?urls.primaryName=v2#/>`__

        Raises a :class:`Py42BadRequestError` when a user already exists in the Departing Employee \
            detection list.

        Args:
            user_id (str or int): The Code42 userUid of the user you want to add to the departing \
                employees list.
            departure_date (str or datetime, optional): Date in yyyy-MM-dd format or instance of datetime.
                Date is treated as UTC. Defaults to None.

        Returns:
            :class:`py42.response.Py42Response`
        """
        if isinstance(departure_date, datetime):
            departure_date = departure_date.strftime(_DATE_FORMAT)
        if self._user_profile_service.create_if_not_exists(user_id):
            tenant_id = self._user_context.get_current_tenant_id()
            data = {
                u"tenantId": tenant_id,
                u"userId": user_id,
                u"departureDate": departure_date,
            }
            uri = self._uri_prefix.format(u"add")
            try:
                return self._connection.post(uri, json=data)
            except Py42BadRequestError as err:
                handle_user_already_added_error(err, user_id,
                                                u"departing-employee list")
                raise
Example #3
0
    def add(self, user_id):
        """Adds a user to the High Risk Employee detection list.

        Raises a :class:`Py42UserAlreadyAddedError` when a user already exists in the High Risk Employee
        detection list.
        `REST Documentation <https://developer.code42.com/api/#operation/HighRiskEmployeeControllerV2_AddEmployee>`__

        Args:
            user_id (str or int): The Code42 userUid of the user you want to add to the High Risk
                Employee detection list.

        Returns:
            :class:`py42.response.Py42Response`
        """
        tenant_id = self._user_context.get_current_tenant_id()
        try:
            return self._add_high_risk_employee(tenant_id, user_id)
        except Py42BadRequestError as err:
            handle_user_already_added_error(err, user_id, u"high-risk-employee list")
            raise
    def add(self, user_id):
        """Adds a user to the High Risk Employee detection list. Creates a detection list user
        profile if one didn't already exist.

        Raises a :class:`Py42BadRequestError` when a user already exists in the High Risk Employee
        detection list.

        Args:
            user_id (str or int): The Code42 userUid of the user you want to add to the High Risk
                Employee detection list.

        Returns:
            :class:`py42.response.Py42Response`
        """
        if self._user_profile_service.create_if_not_exists(user_id):
            tenant_id = self._user_context.get_current_tenant_id()
            try:
                return self._add_high_risk_employee(tenant_id, user_id)
            except Py42BadRequestError as err:
                handle_user_already_added_error(err, user_id,
                                                u"high-risk-employee list")
                raise