<commit_before>/*
 * Copyright (c) 2010 iceScrum Technologies.
 *
 * This file is part of iceScrum.
 *
 * iceScrum is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License.
 *
 * iceScrum is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with iceScrum.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *
 * <NAME> (<EMAIL>)
 * <NAME> (<EMAIL>)
 * <NAME> (<EMAIL>)
 *
 */

package org.icescrum.web.presentation

import org.springframework.web.servlet.support.RequestContextUtils as RCU

import grails.converters.JSON
import grails.plugins.springsecurity.Secured
import org.apache.commons.io.FilenameUtils
import org.icescrum.core.domain.Product
import org.icescrum.core.domain.User
import org.icescrum.core.support.ProgressSupport
import org.icescrum.web.upload.AjaxMultipartResolver
import org.springframework.mail.MailException
import org.icescrum.core.domain.Sprint
import grails.plugin.springcache.annotations.Cacheable
import org.springframework.security.acls.domain.BasePermission
import org.icescrum.core.domain.preferences.ProductPreferences
import org.codehaus.groovy.grails.plugins.DefaultGrailsPluginManager
import org.codehaus.groovy.grails.plugins.GrailsPlugin

class ScrumOSController {

    def springSecurityService
    def productService
    def menuBarSupport
    def notificationEmailService
    def securityService
    def uiDefinitionService

    def licenseService

    def index = {
        def currentUserInstance = null

        def locale = params.lang ?: null
        try {
            def localeAccept = request.getHeader("accept-language")?.split(",")
            if (localeAccept)
                localeAccept = localeAccept[0]?.split("-")

            if (localeAccept?.size() > 0) {
                locale = params.lang ?: localeAccept[0].toString()
            }
        } catch (Exception e) {}

        if (springSecurityService.isLoggedIn()) {
            currentUserInstance = User.get(springSecurityService.principal.id)
            if (locale != currentUserInstance.preferences.language || RCU.getLocale(request).toString() != currentUserInstance.preferences.language) {
                RCU.getLocaleResolver(request).setLocale(request, response, new Locale(currentUserInstance.preferences.language))
            }
        } else {
            if (locale) {
                RCU.getLocaleResolver(request).setLocale(request, response, new Locale(locale))
            }
        }
        def currentProductInstance = params.product ? Product.get(params.long('product')) : null

        if (currentProductInstance?.preferences?.hidden && !securityService.inProduct(currentProductInstance, springSecurityService.authentication) && !securityService.stakeHolder(currentProductInstance,springSecurityService.authentication,false)){
            redirect(action:'error403',controller:'errors')
            return
        }

        if (currentProductInstance && currentUserInstance && !securityService.hasRoleAdmin(currentUserInstance) && currentUserInstance.preferences.lastProductOpened != currentProductInstance.pkey){
            currentUserInstance.preferences.lastProductOpened = currentProductInstance.pkey
            currentUserInstance.save()
        }
        //For PO / SM : WRITE - TM / SH : READ
        def products = currentUserInstance ? Product.findAllByRole(currentUserInstance, [BasePermission.WRITE,BasePermission.READ], [cache:true, max:11]) : []
        def pCount = products?.size()

        [user: currentUserInstance,
                lang: RCU.getLocale(request).toString().substring(0, 2),
                product: currentProductInstance,
                publicProductsExists: ProductPreferences.countByHidden(false,[cache:true]) ? true : false,
                productFilteredsListCount: pCount,
                productFilteredsList: pCount > 9 ? products?.subList(0,9) : products]
    }


    def openWidget = {
        if (!params.window) {
            render(status: 400, contentType: 'application/json', text: [notice: [text: message(code: 'is.error.no.widget')]] as JSON)
            return
        }


        def uiRequested = params.window
        def uiDefinition = uiDefinitionService.getDefinitionById(uiRequested)
        if (uiDefinition) {
            def paramsWidget = null
            if (params.product) {
                paramsWidget = [product: params.product]
            }
            def url = createLink(controller: params.window, action: uiDefinition.widget?.init, params: paramsWidget).toString() - request.contextPath
            if (!menuBarSupport.permissionDynamicBar(url)) {
                session['widgetsList'].remove(params.window)
                render(status: 400)
                return
            }

            if (!
            session['widgetsList']?.contains(params.window)) {
                session['widgetsList'] = session['widgetsList'] ?: []
                session['widgetsList'].add(params.window)
            }
            render is.widget([
                    id: params.window,
                    hasToolbar: uiDefinition.widget?.toolbar,
                    closeable: uiDefinition.widget?.closeable,
                    sortable: uiDefinition.widget?.sortable,
                    windowable: uiDefinition.window ? true : false,
                    height: uiDefinition.widget?.height,
                    hasTitleBarContent: uiDefinition.widget?.titleBarContent,
                    title: message(code: uiDefinition.widget?.title),
                    init: uiDefinition.widget?.init
            ], {})
        }
    }

    def closeWindow = {
        session['currentWindow'] = null
        render(status: '200')
    }

    def closeWidget = {
        if (session['widgetsList']?.contains(params.window))
            session['widgetsList'].remove(params.window);
        render(status: 200)
    }

    def openWindow = {
        if (!params.window) {
            render(status: 400, contentType: 'application/json', text: [notice: [text: message(code: 'is.error.no.window')]] as JSON)
            return
        }
        session['currentWindow'] = params.window
        session['currentView'] = session['currentView'] ?: springSecurityService.isLoggedIn() ? 'postitsView' : 'tableView'
<commit_msg>revert cacheable<commit_after>/*
 * Copyright (c) 2010 iceScrum Technologies.
 *
 * This file is part of iceScrum.
 *
 * iceScrum is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License.
 *
 * iceScrum is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with iceScrum.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *
 * <NAME> (<EMAIL>)
 * <NAME> (<EMAIL>)
 * <NAME> (<EMAIL>)
 *
 */

package org.icescrum.web.presentation

import org.springframework.web.servlet.support.RequestContextUtils as RCU

import grails.converters.JSON
import grails.plugins.springsecurity.Secured
import org.apache.commons.io.FilenameUtils
import org.icescrum.core.domain.Product
import org.icescrum.core.domain.User
import org.icescrum.core.support.ProgressSupport
import org.icescrum.web.upload.AjaxMultipartResolver
import org.springframework.mail.MailException
import org.icescrum.core.domain.Sprint
import grails.plugin.springcache.annotations.Cacheable
import org.springframework.security.acls.domain.BasePermission
import org.icescrum.core.domain.preferences.ProductPreferences
import org.codehaus.groovy.grails.plugins.DefaultGrailsPluginManager
import org.codehaus.groovy.grails.plugins.GrailsPlugin

class ScrumOSController {

    def springSecurityService
    def productService
    def menuBarSupport
    def notificationEmailService
    def securityService
    def uiDefinitionService

    def licenseService

    def index = {
        def currentUserInstance = null

        def locale = params.lang ?: null
        try {
            def localeAccept = request.getHeader("accept-language")?.split(",")
            if (localeAccept)
                localeAccept = localeAccept[0]?.split("-")

            if (localeAccept?.size() > 0) {
                locale = params.lang ?: localeAccept[0].toString()
            }
        } catch (Exception e) {}

        if (springSecurityService.isLoggedIn()) {
            currentUserInstance = User.get(springSecurityService.principal.id)
            if (locale != currentUserInstance.preferences.language || RCU.getLocale(request).toString() != currentUserInstance.preferences.language) {
                RCU.getLocaleResolver(request).setLocale(request, response, new Locale(currentUserInstance.preferences.language))
            }
        } else {
            if (locale) {
                RCU.getLocaleResolver(request).setLocale(request, response, new Locale(locale))
            }
        }
        def currentProductInstance = params.product ? Product.get(params.long('product')) : null

        if (currentProductInstance?.preferences?.hidden && !securityService.inProduct(currentProductInstance, springSecurityService.authentication) && !securityService.stakeHolder(currentProductInstance,springSecurityService.authentication,false)){
            redirect(action:'error403',controller:'errors')
            return
        }

        if (currentProductInstance && currentUserInstance && !securityService.hasRoleAdmin(currentUserInstance) && currentUserInstance.preferences.lastProductOpened != currentProductInstance.pkey){
            currentUserInstance.preferences.lastProductOpened = currentProductInstance.pkey
            currentUserInstance.save()
        }
        //For PO / SM : WRITE - TM / SH : READ
        def products = currentUserInstance ? Product.findAllByRole(currentUserInstance, [BasePermission.WRITE,BasePermission.READ], [cache:true, max:11]) : []
        def pCount = products?.size()

        [user: currentUserInstance,
                lang: RCU.getLocale(request).toString().substring(0, 2),
                product: currentProductInstance,
                publicProductsExists: ProductPreferences.countByHidden(false,[cache:true]) ? true : false,
                productFilteredsListCount: pCount,
                productFilteredsList: pCount > 9 ? products?.subList(0,9) : products]
    }


    def openWidget = {
        if (!params.window) {
            render(status: 400, contentType: 'application/json', text: [notice: [text: message(code: 'is.error.no.widget')]] as JSON)
            return
        }


        def uiRequested = params.window
        def uiDefinition = uiDefinitionService.getDefinitionById(uiRequested)
        if (uiDefinition) {
            def paramsWidget = null
            if (params.product) {
                paramsWidget = [product: params.product]
            }
            def url = createLink(controller: params.window, action: uiDefinition.widget?.init, params: paramsWidget).toString() - request.contextPath
            if (!menuBarSupport.permissionDynamicBar(url)) {
                session['widgetsList'].remove(params.window)
                render(status: 400)
                return
            }

            if (!
            session['widgetsList']?.contains(params.window)) {
                session['widgetsList'] = session['widgetsList'] ?: []
                session['widgetsList'].add(params.window)
            }
            render is.widget([
                    id: params.window,
                    hasToolbar: uiDefinition.widget?.toolbar,
                    closeable: uiDefinition.widget?.closeable,
                    sortable: uiDefinition.widget?.sortable,
                    windowable: uiDefinition.window ? true : false,
                    height: uiDefinition.widget?.height,
                    hasTitleBarContent: uiDefinition.widget?.titleBarContent,
                    title: message(code: uiDefinition.widget?.title),
                    init: uiDefinition.widget?.init
            ], {})
        }
    }

    def closeWindow = {
        session['currentWindow'] = null
        render(status: 200)
    }

    def closeWidget = {
        if (session['widgetsList']?.contains(params.window))
            session['widgetsList'].remove(params.window);
        render(status: 200)
    }

    def openWindow = {
        if (!params.window) {
            render(status: 400, contentType: 'application/json', text: [notice: [text: message(code: 'is.error.no.window')]] as JSON)
            return
        }
        session['currentWindow'] = params.window
        session['currentView'] = session['currentView'] ?: springSecurityService.isLoggedIn() ? 'postitsView' : 'tableView'

{'fraction_non_alphanumeric': 0.10148309869758337, 'fraction_numerical': 0.004968757057893548, 'mean_word_length': 2.69, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '7153370', 'n_tokens_mistral': 3498, 'n_tokens_neox': 3336, 'n_words': 747}