Restrict the access to tasks for Tolokers.
Connect the Toloka-Kit library to your script.
import toloka.client as toloka
Replace the sample API key with your own one.
toloka_client = toloka.TolokaClient('PlaceYourRealApiKey_Here', 'PRODUCTION');
Find out the ID of the pool to which you want to restrict access for a Toloker. Use the set_user_restriction()
method with the pool ID as an argument to the PoolUserRestriction
collector class to restrict access to it to the Toloker with the ID specified in the request.
pool_restriction = toloka_client.set_user_restriction(
toloka.user_restriction.PoolUserRestriction(
user_id='1a5d5299e5a1d0a47605f51191e09ffc',
private_comment='Banning Toloker access to pool',
pool_id='38955320'
)
)
Find out the ID of the project to which you want to restrict access for a Toloker. Use the set_user_restriction()
method with the project ID as an argument to the ProjectUserRestriction
collector class to restrict access to it to the Toloker with the ID specified in the request.
project_restriction = toloka_client.set_user_restriction(
toloka.user_restriction.ProjectUserRestriction(
user_id='1f66ac40c616b717bbffce2a70dfe1f2',
private_comment='Banning Toloker access to project',
project_id='120798'
)
)
Use the set_user_restriction()
method with the AllProjectsUserRestriction
collector class to restrict access to all your projects to the Toloker with the ID specified in the request.
all_projects_restriction = toloka_client.set_user_restriction(
toloka.user_restriction.AllProjectsUserRestriction(
user_id='240d5b7897f98c119cd892e34295587e',
private_comment='Banning Toloker access to all projects'
)
)
You can specify the will_expire
argument for all the collector classes above (PoolUserRestriction
, ProjectUserRestriction
, or AllProjectsUserRestriction
). It defines the date when the ban will be removed from the Toloker. If you don't set it, the ban will be permanent.
The set_user_restriction()
request will return the UserRestriction class object. You can use its attributes to print the information you need.
print(pool_restriction.id, pool_restriction.created)print(project_restriction.id, project_restriction.created)print(all_projects_restriction.id, all_projects_restriction.created)
You should get an output with the IDs of the bans and the ban creation date and time which looks like this.
163294517 2023-07-18 15:31:27.945000+00:00163294518 2023-07-18 15:31:28.459000+00:00163294519 2023-07-18 15:31:29.992000+00:00
import toloka.client as tolokatoloka_client = toloka.TolokaClient('PlaceYourRealApiKey_Here', 'PRODUCTION')pool_restriction = toloka_client.set_user_restriction( toloka.user_restriction.PoolUserRestriction( user_id='1a5d5299e5a1d0a47605f51191e09ffc', private_comment='Banning Toloker access to pool', pool_id='38955320' ))project_restriction = toloka_client.set_user_restriction( toloka.user_restriction.ProjectUserRestriction( user_id='1f66ac40c616b717bbffce2a70dfe1f2', private_comment='Banning Toloker access to project', project_id='120798' ))all_projects_restriction = toloka_client.set_user_restriction( toloka.user_restriction.AllProjectsUserRestriction( user_id='240d5b7897f98c119cd892e34295587e', private_comment='Banning Toloker access to all projects' ))print(pool_restriction.id, pool_restriction.created)print(project_restriction.id, project_restriction.created)print(all_projects_restriction.id, all_projects_restriction.created)
Last updated: July 19, 2023