<commit_before>/*
 * Contributors:
 *     <NAME> <<EMAIL>>
 */
package ca.firstvoices.operations;


import ca.firstvoices.utils.FVRegistrationUtilities;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuxeo.ecm.automation.core.Constants;
import org.nuxeo.ecm.automation.core.annotations.Context;
import org.nuxeo.ecm.automation.core.annotations.Operation;
import org.nuxeo.ecm.automation.core.annotations.OperationMethod;
import org.nuxeo.ecm.automation.core.annotations.Param;
import org.nuxeo.ecm.core.api.CoreSession;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.platform.usermanager.UserManager;
import org.nuxeo.ecm.user.registration.DocumentRegistrationInfo;
import org.nuxeo.ecm.user.registration.UserRegistrationService;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import static org.nuxeo.ecm.user.invite.UserInvitationService.ValidationMethod;

@Operation(id = FVQuickUserRegistration.ID, category = Constants.CAT_USERS_GROUPS, label = "Guest self registration",
        description = "Starts guest registration.")
public class FVQuickUserRegistration {

    public static final String ID = "User.SelfRegistration";
    private static final Log log = LogFactory.getLog(FVQuickUserRegistration.class);

    @Context
    protected UserManager userManager;

    @Context
    protected UserRegistrationService registrationService;

    @Context
    protected CoreSession session;

    @Param(name ="docInfo", required = false)
    protected DocumentRegistrationInfo docInfo = null;

    @Param(name = "validationMethod", required = false)
    protected ValidationMethod validationMethod = ValidationMethod.EMAIL;

    @Param(name = "autoAccept", required = false)
    protected boolean autoAccept = true; // it is ignored

    @Param(name = "info", required = false)
    protected Map<String, Serializable> info = new HashMap<>();

    @Param(name = "comment", required = false)
    protected String comment;



    @OperationMethod
    public String run( DocumentModel registrationRequest ) throws Exception
    {
        FVRegistrationUtilities utilCommon = new FVRegistrationUtilities();

        /*

            This operation has for most part similar code to sister operation UserInvite.
            The main difference is in conditions we apply for both.
            Common code is split into 2 parts
            - preCondition
            - postCondition
            Each of the operations executes it own, context specific conditions and any other operations
            following if appropriate.
            In this case it is sending of emails to both user and LanguageAdministrator informing them about actions.

         */
        utilCommon.preCondition( registrationRequest, session, userManager );

        utilCommon.QuickUserRegistrationCondition( registrationRequest, session );

        String registrationId = utilCommon.postCondition( registrationService,
                registrationRequest,
                info,
                comment,
                validationMethod,
                true ); // we always autoAccept quick registration

        return registrationId;
    }

}
<commit_msg>Added age field for self registration.<commit_after>/*
 * Contributors:
 *     <NAME> <<EMAIL>>
 */
package ca.firstvoices.operations;


import ca.firstvoices.utils.FVRegistrationUtilities;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuxeo.ecm.automation.core.Constants;
import org.nuxeo.ecm.automation.core.annotations.Context;
import org.nuxeo.ecm.automation.core.annotations.Operation;
import org.nuxeo.ecm.automation.core.annotations.OperationMethod;
import org.nuxeo.ecm.automation.core.annotations.Param;
import org.nuxeo.ecm.core.api.CoreSession;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.platform.usermanager.UserManager;
import org.nuxeo.ecm.user.registration.DocumentRegistrationInfo;
import org.nuxeo.ecm.user.registration.UserRegistrationService;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import static org.nuxeo.ecm.user.invite.UserInvitationService.ValidationMethod;

@Operation(id = FVQuickUserRegistration.ID, category = Constants.CAT_USERS_GROUPS, label = "Guest self registration",
        description = "Starts guest registration.")
public class FVQuickUserRegistration {

    public static final String ID = "User.SelfRegistration";
    private static final Log log = LogFactory.getLog(FVQuickUserRegistration.class);

    @Context
    protected UserManager userManager;

    @Context
    protected UserRegistrationService registrationService;

    @Context
    protected CoreSession session;

    @Param(name ="docInfo", required = false)
    protected DocumentRegistrationInfo docInfo = null;

    @Param(name = "validationMethod", required = false)
    protected ValidationMethod validationMethod = ValidationMethod.EMAIL;

    @Param(name = "ageRange", required=false)
    protected String ageRange;

    @Param(name = "info", required = false)
    protected Map<String, Serializable> info = new HashMap<>();

    @Param(name = "comment", required = false)
    protected String comment;



    @OperationMethod
    public String run( DocumentModel registrationRequest ) throws Exception
    {
        FVRegistrationUtilities utilCommon = new FVRegistrationUtilities();

        /*

            This operation has for most part similar code to sister operation UserInvite.
            The main difference is in conditions we apply for both.
            Common code is split into 2 parts
            - preCondition
            - postCondition
            Each of the operations executes it own, context specific conditions and any other operations
            following if appropriate.
            In this case it is sending of emails to both user and LanguageAdministrator informing them about actions.

         */
        utilCommon.preCondition( registrationRequest, session, userManager );

        utilCommon.QuickUserRegistrationCondition( registrationRequest, session );

        String registrationId = utilCommon.postCondition( registrationService,
                registrationRequest,
                info,
                comment,
                validationMethod,
                true ); // we always autoAccept quick registration

        return registrationId;
    }

}

{'fraction_non_alphanumeric': 0.07790192427063936, 'fraction_numerical': 0.00031036623215394165, 'mean_word_length': 3.4602076124567476, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7325118', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1609, 'n_words': 448}