A simple example code: function CaptchaReset(username)
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import com.atlassian.jira.component.ComponentAccessor
import groovy.sql.Sql
import org.ofbiz.core.entity.ConnectionFactory
import org.ofbiz.core.entity.DelegatorInterface
import java.sql.Connection
def delegator = (DelegatorInterface) ComponentAccessor.getComponent(DelegatorInterface)
String helperName = delegator.getGroupHelperName("default")
@BaseScript CustomEndpointDelegate delegate
CaptchaReset(httpMethod: "GET", groups: ["jira-users"]) { MultivaluedMap queryParams->
def username = queryParams.getFirst("username") as String
if ( username == null ) { return Response.serverError().entity([error:"NO_USERNAME"]).build();}
def sqlStmt = "update cwd_user_attributes set attribute_value = '0' where user_id = (select max(id) from cwd_user where user_name = '$username') and attribute_name = 'login.totalFailedCount';"
def sqlStmt2 = "update cwd_user_attributes set attribute_value = '0' where user_id = (select max(id) from cwd_user where user_name = '$username') and attribute_name = 'login.currentFailedCount';"
Connection conn = ConnectionFactory.getConnection(helperName)
Sql sql = new Sql(conn)
try {
StringBuffer sb = new StringBuffer()
sql.execute(sqlStmt)
sql.execute(sqlStmt2)
}
finally {
sql.close()
}
return Response.ok(new JsonBuilder([result: "OK"]).toString()).build();
}
Example query: /rest/scriptrunner/latest/custom/CaptchaReset?username=mraddon
Example result:
{"result":"OK"}
By MrAddon
IMPORTANT NOTE: If we have more than one Directory, we need to change the SQL updates to only apply to the enabled one!
Example: (Note the DIRECTORY_ID = ‘10800’ in the Subquery)
More info: https://developer.atlassian.com/server/jira/platform/database-user-and-group-tables/
LikeLike