<commit_before>package stackoverflow.user

import grails.plugin.springsecurity.annotation.Secured
import grails.rest.RestfulController
import grails.transaction.Transactional
import grails.web.http.HttpHeaders
import stackoverflow.Feature
import stackoverflow.Role
import stackoverflow.User

import static org.springframework.http.HttpStatus.CREATED
import static org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE

@Secured(['ROLE_ANONYMOUS'])
@Transactional(readOnly = true)
class UserController extends RestfulController {

    static responseFormats = ['json', 'xml']

    UserController() {
        super(User)
    }

    // GET LIST
    def index(Integer max) {
        if(!Feature.findByName("User").getEnable()) {
            render status: SERVICE_UNAVAILABLE
        }

        params.max = Math.min(max ?: 10, 100)
        respond User.list(params), model:[questionCount: User.count()]
    }

    // GET WITH ID
    def show() {
        if(!Feature.findByName("User").getEnable()) {
            render status: SERVICE_UNAVAILABLE
        }

        respond queryForResource(params.id)
    }

    @Transactional
    def save() {
        if(!Feature.findByName("User").getEnable()) {
            render status: SERVICE_UNAVAILABLE
        }

        // Create resource
        def user = createResource()



        // Verify
        if (user.hasErrors()) {
            transactionStatus.setRollbackOnly()
            respond user.errors, view:'create' // STATUS CODE 422
            return
        }

        // Save
        UserRole.create user, Role.findByAuthority('ROLE_USER')

        saveResource user

        // Send response
        request.withFormat {
            '*' {<commit_msg>Rectification on default user role.<commit_after>package stackoverflow.user

import grails.plugin.springsecurity.annotation.Secured
import grails.rest.RestfulController
import grails.transaction.Transactional
import grails.web.http.HttpHeaders
import stackoverflow.Feature
import stackoverflow.Role
import stackoverflow.User
import stackoverflow.UserRole

import static org.springframework.http.HttpStatus.CREATED
import static org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE

@Secured(['ROLE_ANONYMOUS'])
@Transactional(readOnly = true)
class UserController extends RestfulController {

    static responseFormats = ['json', 'xml']

    UserController() {
        super(User)
    }

    // GET LIST
    def index(Integer max) {
        if(!Feature.findByName("User").getEnable()) {
            render status: SERVICE_UNAVAILABLE
        }

        params.max = Math.min(max ?: 10, 100)
        respond User.list(params), model:[questionCount: User.count()]
    }

    // GET WITH ID
    def show() {
        if(!Feature.findByName("User").getEnable()) {
            render status: SERVICE_UNAVAILABLE
        }

        respond queryForResource(params.id)
    }

    @Transactional
    def save() {
        if(!Feature.findByName("User").getEnable()) {
            render status: SERVICE_UNAVAILABLE
        }

        // Create resource
        def user = createResource()

        // Verify
        if (user.hasErrors()) {
            transactionStatus.setRollbackOnly()
            respond user.errors, view:'create' // STATUS CODE 422
            return
        }

        // Save
        saveResource user

        // Define role
        UserRole.create user, Role.findByAuthority('ROLE_USER')

        // Send response
        request.withFormat {
            '*' {
{'fraction_non_alphanumeric': 0.10037281330656725, 'fraction_numerical': 0.004588471465443074, 'mean_word_length': 2.5303643724696356, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2768251', 'n_tokens_mistral': 978, 'n_tokens_neox': 949, 'n_words': 198}