Skip to content

[Feature] Add params check in createUser Function#11255

Closed
ly1ex wants to merge 13 commits intoapache:devfrom
ly1ex:feat/add-params-check-in-create-user
Closed

[Feature] Add params check in createUser Function#11255
ly1ex wants to merge 13 commits intoapache:devfrom
ly1ex:feat/add-params-check-in-create-user

Conversation

@ly1ex
Copy link
Contributor

@ly1ex ly1ex commented Aug 2, 2022

Purpose of the pull request

close #11277

  • Add params check in createUser Function

Brief change log

  • Add params check in createUser Function

Verify this pull request

This pull request is already covered by existing tests, such as (please describe tests).

@ly1ex
Copy link
Contributor Author

ly1ex commented Aug 2, 2022

PTAL @zhongjiajie

@SbloodyS SbloodyS added the feature new feature label Aug 2, 2022
@SbloodyS SbloodyS added this to the 3.1.0-alpha milestone Aug 2, 2022
@codecov-commenter
Copy link

codecov-commenter commented Aug 2, 2022

Codecov Report

Merging #11255 (d8b6a51) into dev (f8b9aad) will decrease coverage by 0.00%.
The diff coverage is 55.31%.

@@             Coverage Diff              @@
##                dev   #11255      +/-   ##
============================================
- Coverage     39.59%   39.58%   -0.01%     
- Complexity     4689     4696       +7     
============================================
  Files          1014     1014              
  Lines         37918    37910       -8     
  Branches       4238     4235       -3     
============================================
- Hits          15013    15007       -6     
- Misses        21297    21301       +4     
+ Partials       1608     1602       -6     
Impacted Files Coverage Δ
...a/org/apache/dolphinscheduler/dao/entity/User.java 63.76% <16.66%> (-10.37%) ⬇️
...inscheduler/api/service/impl/UsersServiceImpl.java 74.04% <68.57%> (+1.75%) ⬆️
...inscheduler/server/log/LoggerRequestProcessor.java 17.30% <0.00%> (-0.17%) ⬇️
...ver/master/runner/task/ConditionTaskProcessor.java 4.76% <0.00%> (-0.06%) ⬇️
.../server/master/runner/WorkflowExecuteRunnable.java 7.97% <0.00%> (-0.03%) ⬇️
...server/master/runner/task/SwitchTaskProcessor.java 2.52% <0.00%> (-0.03%) ⬇️
...e/dolphinscheduler/server/master/MasterServer.java 0.00% <0.00%> (ø)
...e/dolphinscheduler/server/worker/WorkerServer.java 0.00% <0.00%> (ø)
...r/api/service/impl/ProcessInstanceServiceImpl.java 60.85% <0.00%> (ø)
... and 8 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 2, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

59.0% 59.0% Coverage
0.0% 0.0% Duplication

user.setUserName(userName);
}

if (StringUtils.isNotEmpty(userPassword)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please merge if statement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please merge if statement

Sorry, I don't get your point...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean please fix code smell

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think OK, and merging can lead to unclear exception semantics.
sometimes, code smell needs to be judged based on the actual situation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, agree with Calvin

user.setUserName(userName);
user.setUserPassword(EncryptionUtils.getMd5(userPassword));
user.setEmail(email);
if (StringUtils.isNotEmpty(userName)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @lyleshaw , thx for this improvement. Since you have added several parameters checks, could you please update related unit tests to get those checks covered? Thx

Copy link
Member

@EricGao888 EricGao888 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to update corresponding unit tests to get those new checks covered.

@ly1ex
Copy link
Contributor Author

ly1ex commented Aug 3, 2022

We need to update corresponding unit tests to get those new checks covered.

Got it.

@zhongjiajie
Copy link
Member

@lyleshaw Please add a issue to target this PR, BTW, can we add some separate function from create and update function? I have do the same thing in Tenant and Queue

/**
* Check the queue new object valid or not
*
* @param queue The queue object want to create
*/
private void createQueueValid(Queue queue) throws ServiceException {
if (StringUtils.isEmpty(queue.getQueue())) {
throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.QUEUE);
} else if (StringUtils.isEmpty(queue.getQueueName())) {
throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.QUEUE_NAME);
} else if (checkQueueExist(queue.getQueue())) {
throw new ServiceException(Status.QUEUE_VALUE_EXIST, queue.getQueue());
} else if (checkQueueNameExist(queue.getQueueName())) {
throw new ServiceException(Status.QUEUE_NAME_EXIST, queue.getQueueName());
}
}
/**
* Check queue update object valid or not
*
* @param existsQueue The exists queue object
* @param updateQueue The queue object want to update
*/
private void updateQueueValid(Queue existsQueue, Queue updateQueue) throws ServiceException {
// Check the exists queue and the necessary of update operation, in not exist checker have to use updateQueue to avoid NPE
if (Objects.isNull(existsQueue)) {
throw new ServiceException(Status.QUEUE_NOT_EXIST, updateQueue.getQueue());
} else if (Objects.equals(existsQueue, updateQueue)) {
throw new ServiceException(Status.NEED_NOT_UPDATE_QUEUE);
}
// Check the update queue parameters
else if (StringUtils.isEmpty(updateQueue.getQueue())) {
throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.QUEUE);
} else if (StringUtils.isEmpty(updateQueue.getQueueName())) {
throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.QUEUE_NAME);
} else if (!Objects.equals(updateQueue.getQueue(), existsQueue.getQueue()) && checkQueueExist(updateQueue.getQueue())) {
throw new ServiceException(Status.QUEUE_VALUE_EXIST, updateQueue.getQueue());
} else if (!Objects.equals(updateQueue.getQueueName(), existsQueue.getQueueName()) && checkQueueNameExist(updateQueue.getQueueName())) {
throw new ServiceException(Status.QUEUE_NAME_EXIST, updateQueue.getQueueName());
}
}

@ly1ex
Copy link
Contributor Author

ly1ex commented Aug 3, 2022

Hi all, I have solved the above problems (including adding tests, abstracting to checkParams functions, etc.)
Please feel free to re-review it.
@zhongjiajie @EricGao888

@zhongjiajie
Copy link
Member

Hi all, I have solved the above problems (including adding tests, abstracting to checkParams functions, etc.)
Please feel free to re-review it.
@zhongjiajie @EricGao888

@lyleshaw But I find out we have some failed CI step, could you please make a check?

@zhongjiajie
Copy link
Member

@lyleshaw It seems dwonload jdbc driver error, could you try to rebase on upstream/dev, and force push to restart CI?

@ly1ex ly1ex force-pushed the feat/add-params-check-in-create-user branch from d8b6a51 to d63c5c4 Compare September 5, 2022 14:26
@ly1ex
Copy link
Contributor Author

ly1ex commented Sep 5, 2022

@lyleshaw It seems dwonload jdbc driver error, could you try to rebase on upstream/dev, and force push to restart CI?

I usually use git merge instead of git rebase, hoping things won't go wrong...

@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 5, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

70.7% 70.7% Coverage
0.0% 0.0% Duplication


user.setPhone(phone);
user = new User(userName, userPassword, email, phone, tenantId, state);
if (state == 0 && user.getState() != state && loginUser.getId() == user.getId()) {

Check failure

Code scanning / CodeQL

Reference equality test of boxed types

Suspicious reference comparison of boxed numerical values.
String phone = "123456789";
String phone = "17366666666";
String tenantCode = "tenantCode";
Integer userId = 1;

Check notice

Code scanning / CodeQL

Unread local variable

Variable 'Integer userId' is never read.
xiaoliangyu and others added 10 commits September 23, 2022 15:57
…/api/service/impl/UsersServiceImpl.java

Co-authored-by: Jiajie Zhong <zhongjiajie955@gmail.com>
…/api/service/impl/UsersServiceImpl.java

Co-authored-by: Jiajie Zhong <zhongjiajie955@gmail.com>
…/api/service/impl/UsersServiceImpl.java

Co-authored-by: Jiajie Zhong <zhongjiajie955@gmail.com>
…/api/service/impl/UsersServiceImpl.java

Co-authored-by: Jiajie Zhong <zhongjiajie955@gmail.com>
@ly1ex ly1ex force-pushed the feat/add-params-check-in-create-user branch from 7165802 to fa22386 Compare September 23, 2022 08:04
@caishunfeng caishunfeng modified the milestones: 3.1.0, 3.2.0 Sep 27, 2022
@zhongjiajie zhongjiajie modified the milestones: 3.2.0, 3.3.0 Aug 30, 2023
@github-actions
Copy link

github-actions bot commented Feb 9, 2024

This pull request has been automatically marked as stale because it has not had recent activity for 120 days. It will be closed in 7 days if no further activity occurs.

@github-actions github-actions bot added the Stale label Feb 9, 2024
@github-actions
Copy link

This pull request has been closed because it has not had recent activity. You could reopen it if you try to continue your work, and anyone who are interested in it are encouraged to continue work on this pull request.

@github-actions github-actions bot closed this Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature][API] Add params check in createUser Function

8 participants