Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom text management API #495

Merged
merged 7 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com).
* Copyright (c) 2021-2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 Inc. licenses this file to you under the Apache License,
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -25,8 +25,10 @@ public class BrandingPreferenceManagementConstants {

public static final String BRANDING_PREFERENCE_ERROR_PREFIX = "BPM-";
public static final String BRANDING_PREFERENCE_CONTEXT_PATH = "/branding-preference";
public static final String CUSTOM_TEXT_PREFERENCE_CONTEXT_PATH = "/branding-preference/text";
public static final String QUERY_PARAM_INDICATOR = "?";
public static final String GET_PREFERENCE_COMPONENT_WITH_QUERY_PARAM = "type=%s&name=%s&locale=%s";
public static final String GET_CUSTOM_TEXT_COMPONENT_WITH_QUERY_PARAM = "type=%s&name=%s&screen=%s&locale=%s";
public static final String ORGANIZATION_TYPE = "ORG";
public static final String APPLICATION_TYPE = "APP";
public static final String CUSTOM_TYPE = "CUSTOM";
Expand All @@ -36,6 +38,8 @@ public class BrandingPreferenceManagementConstants {
public static final String BRANDING_PREFERENCE_NOT_EXISTS_ERROR_CODE = "BRANDINGM_00002";
public static final String BRANDING_PREFERENCE_ALREADY_EXISTS_ERROR_CODE = "BRANDINGM_00003";
public static final String BRANDING_PREFERENCE_NOT_ALLOWED_ERROR_CODE = "BRANDINGM_00011";
public static final String CUSTOM_TEXT_PREFERENCE_NOT_EXISTS_ERROR_CODE = "BRANDINGM_00023";
public static final String CUSTOM_TEXT_PREFERENCE_ALREADY_EXISTS_ERROR_CODE = "BRANDINGM_00024";

/**
* Enums for error messages.
Expand All @@ -54,6 +58,14 @@ public enum ErrorMessage {
ERROR_CODE_NOT_ALLOWED_BRANDING_PREFERENCE_CONFIGURATIONS("60004",
"Not allowed branding preference configurations.",
"Requested branding preference configuration: %s is not allowed for the organization."),
ERROR_CODE_INVALID_CUSTOM_TEXT_PREFERENCE("60005",
"Invalid custom text preference configurations.",
"Invalid custom text preference configurations in request"),
ERROR_CODE_CUSTOM_TEXT_PREFERENCE_NOT_EXISTS("60006",
"Custom text preferences are not configured.",
"Custom text preferences are not configured for organization: %s."),
ERROR_CODE_CONFLICT_CUSTOM_TEXT_PREFERENCE("60007", "Custom Text preference already exists.",
"There exists a custom text preference configurations in the organization: %s."),

// Server errors 650xx.
ERROR_CODE_ERROR_GETTING_BRANDING_PREFERENCE("65001",
Expand All @@ -67,7 +79,20 @@ public enum ErrorMessage {
"Server encountered an error while deleting branding preference configurations for organization: %s"),
ERROR_CODE_ERROR_UPDATING_BRANDING_PREFERENCE("65004",
"Unable to update branding preference configurations.",
"Error while updating branding preference configurations for organization: %s.");
"Error while updating branding preference configurations for organization: %s."),
ERROR_CODE_ERROR_GETTING_CUSTOM_TEXT_PREFERENCE("65005",
"Error while getting custom text preference configurations.",
"Error while retrieving custom text preference configurations for organization: %s."),
ERROR_CODE_ERROR_ADDING_CUSTOM_TEXT_PREFERENCE("65006",
"Unable to add custom text preference configurations.",
"Server encountered an error while adding the custom text configurations for organization: %s"),
ERROR_CODE_ERROR_DELETING_CUSTOM_TEXT_PREFERENCE("65007",
"Unable to delete custom text preference configurations.",
"Server encountered an error while deleting custom text configurations for organization: %s"),
ERROR_CODE_ERROR_UPDATING_CUSTOM_TEXT_PREFERENCE("65008",
"Unable to update custom text preference configurations.",
"Error while updating custom text preference configurations for organization: %s.");


private final String code;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com).
* Copyright (c) 2021-2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 Inc. licenses this file to you under the Apache License,
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -25,6 +25,7 @@
import java.util.List;

import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingPreferenceModel;
import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.CustomTextModel;
import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.Error;
import org.wso2.carbon.identity.api.server.branding.preference.management.v1.BrandingPreferenceApiService;

Expand Down Expand Up @@ -68,6 +69,31 @@ public Response addBrandingPreference(@ApiParam(value = "This represents the bra
return delegate.addBrandingPreference(brandingPreferenceModel );
}

@Valid
@POST
@Path("/text")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@ApiOperation(value = "Add custom text for a tenant.", notes = "This API provides the capability to add custom texts for the specified screen & locale.<br> <b>Permission required:</b> <br> * /permission/admin/manage/identity/applicationmgt/update <br> <b>Scope required:</b> <br> * internal_application_mgt_update ", response = CustomTextModel.class, authorizations = {
@Authorization(value = "BasicAuth"),
@Authorization(value = "OAuth2", scopes = {

})
}, tags={ "Custom Text", })
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Successfully created.", response = CustomTextModel.class),
@ApiResponse(code = 400, message = "Invalid input in the request.", response = Error.class),
@ApiResponse(code = 401, message = "Authentication information is missing or invalid.", response = Void.class),
@ApiResponse(code = 403, message = "Access forbidden.", response = Void.class),
@ApiResponse(code = 409, message = "Conflict.", response = Error.class),
@ApiResponse(code = 500, message = "Internal server error.", response = Error.class),
@ApiResponse(code = 501, message = "Not Implemented.", response = Error.class)
})
public Response addCustomText(@ApiParam(value = "This represents the custom text to be added." ,required=true) @Valid CustomTextModel customTextModel) {

return delegate.addCustomText(customTextModel );
}

@Valid
@DELETE

Expand All @@ -87,11 +113,34 @@ public Response addBrandingPreference(@ApiParam(value = "This represents the bra
@ApiResponse(code = 404, message = "Requested resource is not found.", response = Error.class),
@ApiResponse(code = 500, message = "Internal server error.", response = Error.class)
})
public Response deleteBrandingPreference( @Valid@ApiParam(value = "Type to filter the retrieval of themes.", allowableValues="ORG, APP, CUSTOM", defaultValue="ORG") @DefaultValue("ORG") @QueryParam("type") String type, @Valid@ApiParam(value = "Tenant/Application name to filter the retrieval of themes.") @QueryParam("name") String name, @Valid@ApiParam(value = "Locale to filter the retrieval of themes.", defaultValue="en-US") @DefaultValue("en-US") @QueryParam("locale") String locale) {
public Response deleteBrandingPreference( @Valid@ApiParam(value = "Type to filter the retrieval of customizations.", allowableValues="ORG, APP, CUSTOM", defaultValue="ORG") @DefaultValue("ORG") @QueryParam("type") String type, @Valid@ApiParam(value = "Tenant/Application name to filter the retrieval of customizations.") @QueryParam("name") String name, @Valid@ApiParam(value = "Locale to filter the retrieval of customizations.", defaultValue="en-US") @DefaultValue("en-US") @QueryParam("locale") String locale) {

return delegate.deleteBrandingPreference(type, name, locale );
}

@Valid
@DELETE
@Path("/text")

@Produces({ "application/json" })
@ApiOperation(value = "Deletes custom text.", notes = "This API provides the capability to delete the custom texts for the specified screen & locale of a tenant.<br> <b>Permission required:</b> <br> * /permission/admin/manage/identity/applicationmgt/update <br> <b>Scope required:</b> <br> * internal_application_mgt_update ", response = Void.class, authorizations = {
@Authorization(value = "BasicAuth"),
@Authorization(value = "OAuth2", scopes = {

})
}, tags={ "Custom Text", })
@ApiResponses(value = {
@ApiResponse(code = 204, message = "Successfully deleted.", response = Void.class),
@ApiResponse(code = 400, message = "Invalid input in the request.", response = Error.class),
@ApiResponse(code = 401, message = "Authentication information is missing or invalid.", response = Void.class),
@ApiResponse(code = 403, message = "Access forbidden.", response = Void.class),
@ApiResponse(code = 500, message = "Internal server error.", response = Error.class)
})
public Response deleteCustomText( @Valid@ApiParam(value = "Type to filter the retrieval of customizations.", allowableValues="ORG, APP, CUSTOM", defaultValue="ORG") @DefaultValue("ORG") @QueryParam("type") String type, @Valid@ApiParam(value = "Tenant/Application name to filter the retrieval of customizations.") @QueryParam("name") String name, @Valid@ApiParam(value = "Locale to filter the retrieval of customizations.", defaultValue="en-US") @DefaultValue("en-US") @QueryParam("locale") String locale, @Valid@ApiParam(value = "Screen to filter the retrieval of customizations.") @QueryParam("screen") String screen) {

return delegate.deleteCustomText(type, name, locale, screen );
}

@Valid
@GET

Expand All @@ -111,11 +160,33 @@ public Response deleteBrandingPreference( @Valid@ApiParam(value = "Type to fi
@ApiResponse(code = 404, message = "Requested resource is not found.", response = Error.class),
@ApiResponse(code = 500, message = "Internal server error.", response = Error.class)
})
public Response getBrandingPreference( @Valid@ApiParam(value = "Type to filter the retrieval of themes.", allowableValues="ORG, APP, CUSTOM", defaultValue="ORG") @DefaultValue("ORG") @QueryParam("type") String type, @Valid@ApiParam(value = "Tenant/Application name to filter the retrieval of themes.") @QueryParam("name") String name, @Valid@ApiParam(value = "Locale to filter the retrieval of themes.", defaultValue="en-US") @DefaultValue("en-US") @QueryParam("locale") String locale) {
public Response getBrandingPreference( @Valid@ApiParam(value = "Type to filter the retrieval of customizations.", allowableValues="ORG, APP, CUSTOM", defaultValue="ORG") @DefaultValue("ORG") @QueryParam("type") String type, @Valid@ApiParam(value = "Tenant/Application name to filter the retrieval of customizations.") @QueryParam("name") String name, @Valid@ApiParam(value = "Locale to filter the retrieval of customizations.", defaultValue="en-US") @DefaultValue("en-US") @QueryParam("locale") String locale) {

return delegate.getBrandingPreference(type, name, locale );
}

@Valid
@GET
@Path("/text")

@Produces({ "application/json" })
@ApiOperation(value = "Get Custom text of a tenant.", notes = "This API provides the capability to retrieve the existing custom text configurations of a tenant for the specified screen and locale.<br> If there is no custom texts available for the requested locale, API will check for the default locale('en-US') and return it.<br> <b>Permission required:</b> <br> * None <br> <b>Scope required:</b> <br> * None ", response = CustomTextModel.class, authorizations = {
@Authorization(value = "BasicAuth"),
@Authorization(value = "OAuth2", scopes = {

})
}, tags={ "Custom Text", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK", response = CustomTextModel.class),
@ApiResponse(code = 400, message = "Invalid input in the request.", response = Error.class),
@ApiResponse(code = 404, message = "Requested resource is not found.", response = Error.class),
@ApiResponse(code = 500, message = "Internal server error.", response = Error.class)
})
public Response getCustomText( @Valid@ApiParam(value = "Type to filter the retrieval of customizations.", allowableValues="ORG, APP, CUSTOM", defaultValue="ORG") @DefaultValue("ORG") @QueryParam("type") String type, @Valid@ApiParam(value = "Tenant/Application name to filter the retrieval of customizations.") @QueryParam("name") String name, @Valid@ApiParam(value = "Locale to filter the retrieval of customizations.", defaultValue="en-US") @DefaultValue("en-US") @QueryParam("locale") String locale, @Valid@ApiParam(value = "Screen to filter the retrieval of customizations.") @QueryParam("screen") String screen) {

return delegate.getCustomText(type, name, locale, screen );
}

@Valid
@GET
@Path("/resolve")
Expand All @@ -135,11 +206,33 @@ public Response getBrandingPreference( @Valid@ApiParam(value = "Type to filte
@ApiResponse(code = 404, message = "Requested resource is not found.", response = Error.class),
@ApiResponse(code = 500, message = "Internal server error.", response = Error.class)
})
public Response resolveBrandingPreference( @Valid@ApiParam(value = "Type to filter the retrieval of themes.", allowableValues="ORG, APP, CUSTOM", defaultValue="ORG") @DefaultValue("ORG") @QueryParam("type") String type, @Valid@ApiParam(value = "Tenant/Application name to filter the retrieval of themes.") @QueryParam("name") String name, @Valid@ApiParam(value = "Locale to filter the retrieval of themes.", defaultValue="en-US") @DefaultValue("en-US") @QueryParam("locale") String locale) {
public Response resolveBrandingPreference( @Valid@ApiParam(value = "Type to filter the retrieval of customizations.", allowableValues="ORG, APP, CUSTOM", defaultValue="ORG") @DefaultValue("ORG") @QueryParam("type") String type, @Valid@ApiParam(value = "Tenant/Application name to filter the retrieval of customizations.") @QueryParam("name") String name, @Valid@ApiParam(value = "Locale to filter the retrieval of customizations.", defaultValue="en-US") @DefaultValue("en-US") @QueryParam("locale") String locale) {

return delegate.resolveBrandingPreference(type, name, locale );
}

@Valid
@GET
@Path("/text/resolve")

@Produces({ "application/json" })
@ApiOperation(value = "Resolve custom text of an organization.", notes = "This API provides the capability to retrieve the custom text configurations of an organization/specific application.<br> If there is no custom text available for the requested locale, API will check for the default locale('en-US') and return it.<br> If there is no custom text available for the requested organization, API will check for the parent organization's custom text configurations and return it.<br> <b>Permission required:</b> <br> * None <br> <b>Scope required:</b> <br> * None ", response = CustomTextModel.class, authorizations = {
@Authorization(value = "BasicAuth"),
@Authorization(value = "OAuth2", scopes = {

})
}, tags={ "Custom Text", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK", response = CustomTextModel.class),
@ApiResponse(code = 400, message = "Invalid input in the request.", response = Error.class),
@ApiResponse(code = 404, message = "Requested resource is not found.", response = Error.class),
@ApiResponse(code = 500, message = "Internal server error.", response = Error.class)
})
public Response resolveCustomText( @Valid@ApiParam(value = "Type to filter the retrieval of customizations.", allowableValues="ORG, APP, CUSTOM", defaultValue="ORG") @DefaultValue("ORG") @QueryParam("type") String type, @Valid@ApiParam(value = "Tenant/Application name to filter the retrieval of customizations.") @QueryParam("name") String name, @Valid@ApiParam(value = "Locale to filter the retrieval of customizations.", defaultValue="en-US") @DefaultValue("en-US") @QueryParam("locale") String locale, @Valid@ApiParam(value = "Screen to filter the retrieval of customizations.") @QueryParam("screen") String screen) {

return delegate.resolveCustomText(type, name, locale, screen );
}

@Valid
@PUT

Expand All @@ -150,7 +243,7 @@ public Response resolveBrandingPreference( @Valid@ApiParam(value = "Type to f
@Authorization(value = "OAuth2", scopes = {

})
}, tags={ "Branding Preference" })
}, tags={ "Branding Preference", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully updated", response = BrandingPreferenceModel.class),
@ApiResponse(code = 400, message = "Invalid input in the request.", response = Error.class),
Expand All @@ -164,4 +257,28 @@ public Response updateBrandingPreference(@ApiParam(value = "This represents the
return delegate.updateBrandingPreference(brandingPreferenceModel );
}

@Valid
@PUT
@Path("/text")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@ApiOperation(value = "Update custom text of a tenant.", notes = "This API provides the capability to update the custom texts for the specified screen & locale.<br> <b>Permission required:</b> <br> * /permission/admin/manage/identity/applicationmgt/update <br> <b>Scope required:</b> <br> * internal_application_mgt_update ", response = CustomTextModel.class, authorizations = {
@Authorization(value = "BasicAuth"),
@Authorization(value = "OAuth2", scopes = {

})
}, tags={ "Custom Text" })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully updated", response = CustomTextModel.class),
@ApiResponse(code = 400, message = "Invalid input in the request.", response = Error.class),
@ApiResponse(code = 401, message = "Authentication information is missing or invalid.", response = Void.class),
@ApiResponse(code = 403, message = "Access forbidden.", response = Void.class),
@ApiResponse(code = 404, message = "Requested resource is not found.", response = Error.class),
@ApiResponse(code = 500, message = "Internal server error.", response = Error.class)
})
public Response updateCustomText(@ApiParam(value = "This represents the custom text content to be updated for the specified screen & locale." ,required=true) @Valid CustomTextModel customTextModel) {

return delegate.updateCustomText(customTextModel );
}

}
Loading
Loading