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

REST API: Slug is not created, when API or Organization is created #3373

Closed
matleppa opened this issue Feb 1, 2018 · 5 comments
Closed

REST API: Slug is not created, when API or Organization is created #3373

matleppa opened this issue Feb 1, 2018 · 5 comments

Comments

@matleppa
Copy link
Member

matleppa commented Feb 1, 2018

Description

When API or Organization is created, a slug must be created also (because the slug works as a link to API/Organization).

Problem

Within PR 3140 the way that a slug is formed was changed.
The change is not implemented in Catalog API or in Management API, thus the created API or Organization has not slug and the can not be referred, i.e. their profiles can not be managed.

Solution

Implement similar slug creation functionality into REST APIs as there is in UI related operations.

@matleppa matleppa changed the title REST API: Slug is not created, when API or Ogranization is created REST API: Slug is not created, when API or Organization is created Feb 1, 2018
@deligence-dharmendra deligence-dharmendra self-assigned this Feb 8, 2018
@deligence-dharmendra
Copy link
Contributor

Hi @marla-singer @matleppa, I'm a little bit confused about the below code, My question is, if someone wants to update only organization description and URL using Rest API call then update will be failed.

       // Organization with same name must not already exist
        const duplicateOrganization = Organizations.findOne({ name: bodyParams.name });

        if (duplicateOrganization) {
          const detailLine = 'Duplicate: Organization with same name exists.';
          const idValue = `${duplicateOrganization._id}`;
          return errorMessagePayload(400, detailLine, 'id', idValue);
        }

Please correct me.

@matleppa
Copy link
Member Author

matleppa commented Feb 9, 2018

You took the piece of code from method POST /organizations, right?
That method is used only to create a new Organization and in that case "name" is a mandatory parameter.

The updates are done with method PUT /organization, so there is a checking, if parameter "name" is provided.

@deligence-dharmendra
Copy link
Contributor

@matleppa, No. I have taken the code from PUT/organization. code line number near 520.

@matleppa
Copy link
Member Author

matleppa commented Feb 9, 2018

@deligence-dharmendra

This is what I see in PUT /organization endpoint concerning parameter "name".
Duplicate is checked only in case parameter "name" in included in request (in bodyParams).

  // Validate name, if provided
  if (bodyParams.name) {
    isValid = Organizations.simpleSchema().namedContext().validateOne(
      organizationData, 'name');

    if (!isValid) {
      return errorMessagePayload(400, 'Parameter "name" is erroneous or missing');
    }
    // Organization with same name must not already exist
    const duplicateOrganization = Organizations.findOne({ name: bodyParams.name });
    if (duplicateOrganization) {
      const detailLine = 'Duplicate: Organization with same name exists.';
      const idValue = `${duplicateOrganization._id}`;
      return errorMessagePayload(400, detailLine, 'id', idValue);
    }
  }

@matleppa
Copy link
Member Author

matleppa commented Feb 9, 2018

@deligence-dharmendra @preriasusi
Note! This is to be implemented with (or after) issue 3389.

The goal is not to add a separate DB write for slug when Organization name is updated, but to get all changed (or new) Organization data ready and use only one DB write to get it into DB.

The reason for it is that in APIs we need to be prepared for DB update failures also. In case there are several DB writes, we have to rollback possible previous successful write in case latter write fails.
So it is less work, when only one DB write is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants