Delete function question

I have the function:

contract TaskContract {

  function deleteTask(uint256 taskId, bool isDeleted) external {
        if (taskToOwner[taskId] == msg.sender) {
            tasks[taskId].isDeleted = isDeleted;
            emit DeleteTask(taskId, isDeleted);

I know how to call other smart contract. My question is how to make sure that the contract calling the deleteTask() function has the necessary permissions to delete the task. How to rewrite function with if statement to check it. Any ideas ?

Thank you.

Isn't it the case already? If not, what's the purpose of if (taskToOwner[taskId] == msg.sender) ?

The purpose is that in the other function which is addTask() you map taskToOwner, msg.sender and at the same time the function creates new smart contract. So basically the new smart contract calling deleteTask() and it’s owner need to be able to delete certain task and it’s Id number from main contract.