Skip to content

Commit

Permalink
Merge branch 'feat/show-space' into 'main'
Browse files Browse the repository at this point in the history
✨ (public) Show space details

See merge request decidim/decidim-chatbot/decidim-module-rest_full!9
  • Loading branch information
Hadrien Froger committed Dec 9, 2024
2 parents b7112b0 + d2fe014 commit e2b08c4
Show file tree
Hide file tree
Showing 11 changed files with 2,042 additions and 971 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
decidim-rest_full (0.0.4)
decidim-rest_full (0.0.5)
api-pagination (~> 6.0)
cancancan
decidim-admin (>= 0.28, < 0.30)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,37 @@ def index
).serializable_hash
end

def show
manifest_name = params.require(:manifest_name)
model_class_name = manifest_data(manifest_name)[:model]
raise Decidim::RestFull::ApiException::BadRequest, "manifest not supported: #{manifest_name}" unless Object.const_defined?(model_class_name)

model = model_class_name.constantize
select_transparent = if model.column_names.include? :is_transparent
"#{model.table_name}.is_transparent"
else
"FALSE as is_transparent"
end
query = model.where(organization: current_organization).visible_for(act_as).select(
"#{model.table_name}.created_at",
"#{model.table_name}.updated_at",
"#{model.table_name}.id",
"#{model.table_name}.title",
"#{model.table_name}.subtitle",
"#{model.table_name}.description",
"#{model.table_name}.short_description",
"#{model.table_name}.private_space",
select_transparent,
"'#{manifest_name}' AS manifest_name",
"'#{model_class_name}' AS class_name"
).find(params.require(:id))

render json: SpaceSerializer.new(
query,
params: { only: [], locales: available_locales, host: current_organization.host }
).serializable_hash
end

private

def space_manifest_names
Expand All @@ -69,7 +100,7 @@ def manifest_data(manifest)
when :assemblies
{ model: "Decidim::Assembly", manifest: manifest }
else
raise Decidim::RestFull::ApiException::BadRequest, "manifest not found: #{manifest}"
raise Decidim::RestFull::ApiException::BadRequest, "manifest not supported: #{manifest}"
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
namespace :public do
resources :spaces, only: [:index]
resources :components, only: [:index, :show]

Decidim.participatory_space_registry.manifests.map(&:name).each do |manifest_name|
resources manifest_name.to_sym, only: [:show, :index], controller: "/decidim/api/rest_full/public/spaces" do
collection do
get "/", action: :index, defaults: { manifest_name: manifest_name }
get "/:id", action: :show, defaults: { manifest_name: manifest_name }
end
end
end
end
end
end
Expand Down
241 changes: 241 additions & 0 deletions contrib/decidim-node-client/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2038,6 +2038,76 @@ export const PublicApiAxiosParamCreator = function (
options: localVarRequestOptions,
};
},
/**
*
* @summary Show Participatory Spaces
* @param {number} id
* @param {PublicManifestNameIdGetManifestNameEnum} manifestName
* @param {Array<PublicManifestNameIdGetLocalesEnum>} [locales]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
publicManifestNameIdGet: async (
id: number,
manifestName: PublicManifestNameIdGetManifestNameEnum,
locales?: Array<PublicManifestNameIdGetLocalesEnum>,
options: RawAxiosRequestConfig = {},
): Promise<RequestArgs> => {
// verify required parameter 'id' is not null or undefined
assertParamExists("publicManifestNameIdGet", "id", id);
// verify required parameter 'manifestName' is not null or undefined
assertParamExists(
"publicManifestNameIdGet",
"manifestName",
manifestName,
);
const localVarPath = `/public/{manifest_name}/{id}`
.replace(`{${"id"}}`, encodeURIComponent(String(id)))
.replace(
`{${"manifest_name"}}`,
encodeURIComponent(String(manifestName)),
);
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = {
method: "GET",
...baseOptions,
...options,
};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

// authentication credentialFlowBearer required
// http bearer authentication required
await setBearerAuthToObject(localVarHeaderParameter, configuration);

// authentication resourceOwnerFlowBearer required
// http bearer authentication required
await setBearerAuthToObject(localVarHeaderParameter, configuration);

if (locales) {
localVarQueryParameter["locales[]"] = locales;
}

setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions =
baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {
...localVarHeaderParameter,
...headersFromBaseOptions,
...options.headers,
};

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @summary List Participatory Spaces
Expand Down Expand Up @@ -2315,6 +2385,43 @@ export const PublicApiFp = function (configuration?: Configuration) {
configuration,
)(axios, localVarOperationServerBasePath || basePath);
},
/**
*
* @summary Show Participatory Spaces
* @param {number} id
* @param {PublicManifestNameIdGetManifestNameEnum} manifestName
* @param {Array<PublicManifestNameIdGetLocalesEnum>} [locales]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async publicManifestNameIdGet(
id: number,
manifestName: PublicManifestNameIdGetManifestNameEnum,
locales?: Array<PublicManifestNameIdGetLocalesEnum>,
options?: RawAxiosRequestConfig,
): Promise<
(axios?: AxiosInstance, basePath?: string) => AxiosPromise<SpaceResponse>
> {
const localVarAxiosArgs =
await localVarAxiosParamCreator.publicManifestNameIdGet(
id,
manifestName,
locales,
options,
);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath =
operationServerMap["PublicApi.publicManifestNameIdGet"]?.[
localVarOperationServerIndex
]?.url;
return (axios, basePath) =>
createRequestFunction(
localVarAxiosArgs,
globalAxios,
BASE_PATH,
configuration,
)(axios, localVarOperationServerBasePath || basePath);
},
/**
*
* @summary List Participatory Spaces
Expand Down Expand Up @@ -2458,6 +2565,26 @@ export const PublicApiFactory = function (
)
.then((request) => request(axios, basePath));
},
/**
*
* @summary Show Participatory Spaces
* @param {PublicApiPublicManifestNameIdGetRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
publicManifestNameIdGet(
requestParameters: PublicApiPublicManifestNameIdGetRequest,
options?: RawAxiosRequestConfig,
): AxiosPromise<SpaceResponse> {
return localVarFp
.publicManifestNameIdGet(
requestParameters.id,
requestParameters.manifestName,
requestParameters.locales,
options,
)
.then((request) => request(axios, basePath));
},
/**
*
* @summary List Participatory Spaces
Expand Down Expand Up @@ -2628,6 +2755,34 @@ export interface PublicApiPublicComponentsIdGetRequest {
readonly locales?: Array<PublicComponentsIdGetLocalesEnum>;
}

/**
* Request parameters for publicManifestNameIdGet operation in PublicApi.
* @export
* @interface PublicApiPublicManifestNameIdGetRequest
*/
export interface PublicApiPublicManifestNameIdGetRequest {
/**
*
* @type {number}
* @memberof PublicApiPublicManifestNameIdGet
*/
readonly id: number;

/**
*
* @type {'participatory_processes' | 'assemblies'}
* @memberof PublicApiPublicManifestNameIdGet
*/
readonly manifestName: PublicManifestNameIdGetManifestNameEnum;

/**
*
* @type {Array<'en' | 'bg' | 'ar' | 'ca' | 'cs' | 'da' | 'de' | 'el' | 'eo' | 'es' | 'es-MX' | 'es-PY' | 'et' | 'eu' | 'fa' | 'fi-pl' | 'fi' | 'fr' | 'fr-CA' | 'ga' | 'gl' | 'hr' | 'hu' | 'id' | 'is' | 'it' | 'ja' | 'ko' | 'lb' | 'lt' | 'lv' | 'mt' | 'nl' | 'no' | 'pl' | 'pt' | 'pt-BR' | 'ro' | 'ru' | 'sk' | 'sl' | 'sr' | 'sv' | 'tr' | 'uk' | 'vi' | 'zh-CN' | 'zh-TW'>}
* @memberof PublicApiPublicManifestNameIdGet
*/
readonly locales?: Array<PublicManifestNameIdGetLocalesEnum>;
}

/**
* Request parameters for publicSpacesGet operation in PublicApi.
* @export
Expand Down Expand Up @@ -2816,6 +2971,28 @@ export class PublicApi extends BaseAPI {
.then((request) => request(this.axios, this.basePath));
}

/**
*
* @summary Show Participatory Spaces
* @param {PublicApiPublicManifestNameIdGetRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof PublicApi
*/
public publicManifestNameIdGet(
requestParameters: PublicApiPublicManifestNameIdGetRequest,
options?: RawAxiosRequestConfig,
) {
return PublicApiFp(this.configuration)
.publicManifestNameIdGet(
requestParameters.id,
requestParameters.manifestName,
requestParameters.locales,
options,
)
.then((request) => request(this.axios, this.basePath));
}

/**
*
* @summary List Participatory Spaces
Expand Down Expand Up @@ -2998,6 +3175,70 @@ export type PublicComponentsIdGetLocalesEnum =
/**
* @export
*/
export const PublicManifestNameIdGetManifestNameEnum = {
ParticipatoryProcesses: "participatory_processes",
Assemblies: "assemblies",
} as const;
export type PublicManifestNameIdGetManifestNameEnum =
(typeof PublicManifestNameIdGetManifestNameEnum)[keyof typeof PublicManifestNameIdGetManifestNameEnum];
/**
* @export
*/
export const PublicManifestNameIdGetLocalesEnum = {
En: "en",
Bg: "bg",
Ar: "ar",
Ca: "ca",
Cs: "cs",
Da: "da",
De: "de",
El: "el",
Eo: "eo",
Es: "es",
EsMx: "es-MX",
EsPy: "es-PY",
Et: "et",
Eu: "eu",
Fa: "fa",
FiPl: "fi-pl",
Fi: "fi",
Fr: "fr",
FrCa: "fr-CA",
Ga: "ga",
Gl: "gl",
Hr: "hr",
Hu: "hu",
Id: "id",
Is: "is",
It: "it",
Ja: "ja",
Ko: "ko",
Lb: "lb",
Lt: "lt",
Lv: "lv",
Mt: "mt",
Nl: "nl",
No: "no",
Pl: "pl",
Pt: "pt",
PtBr: "pt-BR",
Ro: "ro",
Ru: "ru",
Sk: "sk",
Sl: "sl",
Sr: "sr",
Sv: "sv",
Tr: "tr",
Uk: "uk",
Vi: "vi",
ZhCn: "zh-CN",
ZhTw: "zh-TW",
} as const;
export type PublicManifestNameIdGetLocalesEnum =
(typeof PublicManifestNameIdGetLocalesEnum)[keyof typeof PublicManifestNameIdGetLocalesEnum];
/**
* @export
*/
export const PublicSpacesGetLocalesEnum = {
En: "en",
Bg: "bg",
Expand Down
2 changes: 1 addition & 1 deletion contrib/decidim-node-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@octree/decidim-sdk",
"version": "0.0.4",
"version": "0.0.5",
"description": "Typescript-fetch client for Decidim Restfull APi",
"keywords": [],
"license": "AGPL-3.0-only",
Expand Down
2 changes: 1 addition & 1 deletion lib/decidim/rest_full/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Decidim
module RestFull
def self.version
"0.0.4" # DO NOT UPDATE MANUALLY
"0.0.5" # DO NOT UPDATE MANUALLY
end

def self.major_minor_version
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "decidim-rest_full",
"private": true,
"version": "0.0.4",
"version": "0.0.5",
"packageManager": "yarn@1.22.22",
"devDependencies": {
"@openapitools/openapi-generator-cli": "^2.15.3",
Expand Down
Loading

0 comments on commit e2b08c4

Please sign in to comment.