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

FOIMOD-2982-Comments Tab - Type of Comments (Peer Review, Internal, General)-New Observation fixes #5383

Merged
merged 1 commit into from
Aug 28, 2024
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
Expand Up @@ -301,7 +301,7 @@ const InputField = ({ cancellor, parentId, child, inputvalue, edit, main, add, f
) : null}
</div>
</div>
{edit &&
{edit && !parentId &&
<Grid item xs={12} lg={6}>
<FormControl component="fieldset">
<RadioGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DisplayComments from './DisplayComments'
import { ActionProvider } from './ActionContext'
import Input from './Input'
import CommentFilter from './CommentFilter'
import { getMinistryRestrictedTagList, getCommentTypeIdByName, setTeamTagList } from "../../../../helper/FOI/helper";
import { getMinistryRestrictedTagList, getCommentTypeIdByName, getCommentTypeFromId } from "../../../../helper/FOI/helper";
import Loading from "../../../../containers/Loading";
//import { CommentTypes } from '../../../../constants/FOI/enum'
import {fetchFOICommentTypes} from "../../../../apiManager/services/FOI/foiMasterDataServices";
Expand Down Expand Up @@ -50,14 +50,13 @@ export const CommentSection = ({

useEffect(() => {
let _commentsbyCategory = filterCommentFn()
let _filteredcomments = filterkeyValue === "" ? _commentsbyCategory : _commentsbyCategory.filter(c => c.text.toLowerCase().indexOf(filterkeyValue.toLowerCase()) > -1)
let _filteredcomments = filterkeyValue === "" ? _commentsbyCategory : (_commentsbyCategory.filter(c => c.text.toLowerCase().indexOf(filterkeyValue.toLowerCase()) > -1
|| getCommentTypeFromId(commentTypes, c.commentTypeId)?.indexOf(filterkeyValue.toLowerCase()) > -1))
let filteredcomments = filterkeyinCommentsandReplies(_commentsbyCategory,_filteredcomments)
setcomments(filteredcomments)
}, [filterValue,commentsArray ,filterkeyValue])
let restrictedReqTaglist = useSelector((state) => state.foiRequests.restrictedReqTaglist);

// console.log("!!ministryAssignedToList:",ministryAssignedToList)
// console.log("!!iaoassignedToList:",iaoassignedToList)

const filterCommentFn = () => {
if(parseInt(filterValue) === -1){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const ConfirmModal= ({
<button
className={`btn-bottom btn-save btn`}
onClick={handleSave}
style={{marginTop:'0px'}}
//disabled={!isIAORestrictedFileManager || isRequestAssignedToTeam()}
>
Save Change
Expand Down
14 changes: 13 additions & 1 deletion forms-flow-web/src/helper/FOI/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,17 @@ const getCommentLabelFromId = (commentTypes, id) => {
return commentType ? commentType.label?.toUpperCase() : "";
};

const getCommentTypeFromId = (commentTypes, id) => {
const commentType = commentTypes.find(type => type.commenttypeid === id);
if(commentType != null && commentType != undefined){
if(commentType.name == "User submitted")
return "general";
else
return commentType.name?.toLowerCase()
}
return "";
};

const setTeamTagList = (bcgovcode) => {
//let fullnameList = getFullnameList();
let iaoFullnameArray = [];
Expand Down Expand Up @@ -600,5 +611,6 @@ export {
getCommentLabelFromId,
getIAOAssignToList,
setTeamTagList,
getIAOTagList
getIAOTagList,
getCommentTypeFromId
};
70 changes: 59 additions & 11 deletions request-management-api/request_api/models/FOIRawRequestComments.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def updatecomment(cls, commentid, foirequestcomment, userid):
comment = dbquery.filter_by(commentid=commentid).order_by(FOIRawRequestComment.commentsversion.desc()).first()
_commentsversion = 0
_existingtaggedusers = []
_commenttypeid = None
if comment is not None :
_commenttypeid = comment.commenttypeid
_existingtaggedusers = comment.taggedusers
Expand Down Expand Up @@ -105,20 +106,67 @@ def updatecomment(cls, commentid, foirequestcomment, userid):
}
)
db.session.execute(updatestmt)
if foirequestcomment["commenttypeid"] != _commenttypeid:
print("updating child comments", foirequestcomment["commenttypeid"])
dbquery.filter_by(parentcommentid=commentid, isactive = True).update(
{
"commenttypeid": foirequestcomment["commenttypeid"],
"updated_at": datetime.now(),
"updatedby": userid
},
synchronize_session=False
db.session.commit()
return DefaultMethodResult(True, 'Updated Comment added', commentid, _existingtaggedusers, _commentsversion, _commenttypeid)
else:
return DefaultMethodResult(True, 'No Comment found', commentid, _existingtaggedusers, _commentsversion, _commenttypeid)

@classmethod
def updatechildcomments(cls, parentcommentid, foirequestcomment, userid):
dbquery = db.session.query(FOIRawRequestComment)
childcomments = dbquery.filter_by(parentcommentid=parentcommentid, isactive = True)
_existingtaggedusers = []
_commentsversion = 0
if childcomments is not None and childcomments.count() > 0:
for comment in childcomments:
_existingtaggedusers = comment.taggedusers
_taggedusers = _existingtaggedusers
_commentsversion = int(comment.commentsversion)
insertstmt = (
insert(FOIRawRequestComment).
values(
commentid= comment.commentid,
requestid=comment.requestid,
version=comment.version,
comment=comment.comment,
taggedusers=_taggedusers,
parentcommentid=comment.parentcommentid,
isactive=True,
created_at=datetime.now(),
createdby=userid,
updated_at=datetime.now(),
updatedby=userid,
commenttypeid= foirequestcomment["commenttypeid"], #comment.commenttypeid,
commentsversion=_commentsversion + 1
)
)
updatestmt = insertstmt.on_conflict_do_update(index_elements=[FOIRawRequestComment.commentid, FOIRawRequestComment.commentsversion],
set_={"requestid": comment.requestid, "version":comment.version, "comment": comment.comment,
"taggedusers":_taggedusers, "parentcommentid":comment.parentcommentid, "isactive":True,
"created_at":datetime.now(), "createdby": userid, "updated_at": datetime.now(), "updatedby": userid,
"commenttypeid": foirequestcomment["commenttypeid"]
}
)
db.session.execute(updatestmt)
db.session.commit()
return DefaultMethodResult(True,'Updated Comment added',parentcommentid, _existingtaggedusers, _commentsversion, childcomments)
else:
return DefaultMethodResult(True,'No Comment found',parentcommentid, _existingtaggedusers, _commentsversion, None)

@classmethod
def deactivatechildcomments(cls, parentcommentid, userid, childcomments):
dbquery = db.session.query(FOIRawRequestComment)
found = False
for child in childcomments:
comment = dbquery.filter_by(commentid=child.commentid, commentsversion=child.commentsversion, parentcommentid=parentcommentid)
if(comment.count() > 0) :
comment.update({FOIRawRequestComment.isactive:False, FOIRawRequestComment.updatedby:userid, FOIRawRequestComment.updated_at:datetime.now()}, synchronize_session = False)
found = True
if found:
db.session.commit()
return DefaultMethodResult(True, 'Updated Comment added', commentid, _existingtaggedusers, _commentsversion)
return DefaultMethodResult(True, 'Reply Comments deactivated for parent', parentcommentid)
else:
return DefaultMethodResult(True, 'No Comment found', commentid, _existingtaggedusers, _commentsversion)
return DefaultMethodResult(False, 'No Reply Comments found for parent', parentcommentid)

@classmethod
def getcomments(cls, requestid) -> DefaultMethodResult:
Expand Down
73 changes: 62 additions & 11 deletions request-management-api/request_api/models/FOIRequestComments.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def updatecomment(cls, commentid, foirequestcomment, userid):
comment = dbquery.filter_by(commentid=commentid).order_by(FOIRequestComment.commentsversion.desc()).first()
_existingtaggedusers = []
_commentsversion = 0
_commenttypeid = None
if comment is not None :
_commenttypeid = comment.commenttypeid
_existingtaggedusers = comment.taggedusers
Expand Down Expand Up @@ -111,20 +112,70 @@ def updatecomment(cls, commentid, foirequestcomment, userid):
}
)
db.session.execute(updatestmt)
if foirequestcomment["commenttypeid"] != _commenttypeid:
print("Comment type changed-updating child comments", foirequestcomment["commenttypeid"])
dbquery.filter_by(parentcommentid=commentid, isactive = True).update(
{
"commenttypeid": foirequestcomment["commenttypeid"],
"updated_at": datetime2.now(),
"updatedby": userid
},
synchronize_session=False
db.session.commit()
return DefaultMethodResult(True,'Updated Comment added',commentid, _existingtaggedusers, _commentsversion, _commenttypeid)
else:
return DefaultMethodResult(True,'No Comment found',commentid, _existingtaggedusers, _commentsversion,_commenttypeid)

@classmethod
def updatechildcomments(cls, parentcommentid, foirequestcomment, userid):
#print("updatecomment:",foirequestcomment)
dbquery = db.session.query(FOIRequestComment)
childcomments = dbquery.filter_by(parentcommentid=parentcommentid, isactive = True)
_existingtaggedusers = []
_commentsversion = 0
_commentids = []
if childcomments is not None and childcomments.count() > 0 :
for comment in childcomments:
_commentids.append(comment.commentid)
_existingtaggedusers = comment.taggedusers
_taggedusers = _existingtaggedusers
_commentsversion = int(comment.commentsversion)
insertstmt = (
insert(FOIRequestComment).
values(
commentid=comment.commentid,
ministryrequestid=comment.ministryrequestid,
version=comment.version,
comment=comment.comment,
taggedusers=_taggedusers,
parentcommentid=comment.parentcommentid,
isactive=True,
created_at=datetime2.now(),
createdby=userid,
updated_at=datetime2.now(),
updatedby=userid,
commenttypeid=foirequestcomment["commenttypeid"],
commentsversion=_commentsversion + 1
)
)
updatestmt = insertstmt.on_conflict_do_update(index_elements=[FOIRequestComment.commentid, FOIRequestComment.commentsversion],
set_={"ministryrequestid": comment.ministryrequestid,"version":comment.version, "comment": comment.comment,
"taggedusers":_taggedusers, "parentcommentid":comment.parentcommentid, "isactive":True,
"created_at":datetime2.now(), "createdby": userid, "updated_at": datetime2.now(), "updatedby": userid,
"commenttypeid": foirequestcomment["commenttypeid"]
}
)
db.session.execute(updatestmt)
db.session.commit()
return DefaultMethodResult(True,'Updated Comment added',parentcommentid, _existingtaggedusers, _commentsversion, childcomments)
else:
return DefaultMethodResult(True,'No Comment found',parentcommentid, _existingtaggedusers, _commentsversion, None)

@classmethod
def deactivatechildcomments(cls, parentcommentid, userid, childcomments):
dbquery = db.session.query(FOIRequestComment)
found = False
for child in childcomments:
comment = dbquery.filter_by(commentid=child.commentid, commentsversion=child.commentsversion, parentcommentid=parentcommentid)
if(comment.count() > 0) :
comment.update({FOIRequestComment.isactive:False, FOIRequestComment.updatedby:userid, FOIRequestComment.updated_at:datetime2.now()}, synchronize_session = False)
found = True
if found:
db.session.commit()
return DefaultMethodResult(True,'Updated Comment added',commentid, _existingtaggedusers, _commentsversion)
return DefaultMethodResult(True, 'Reply Comments deactivated for parent', parentcommentid)
else:
return DefaultMethodResult(True,'No Comment found',commentid, _existingtaggedusers, _commentsversion)
return DefaultMethodResult(False, 'No Reply Comments found for parent', parentcommentid)

@classmethod
def getcomments(cls, ministryrequestid)->DefaultMethodResult:
Expand Down
18 changes: 18 additions & 0 deletions request-management-api/request_api/services/commentservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ def updateministryrequestcomment(self, commentid, data, userid):
commentsversion = result.args[1]
if commentsversion and commentsversion > 0:
deactivateresult = FOIRequestComment.deactivatecomment(commentid, userid, commentsversion)
commenttypeid = result.args[2]
#print("commenttypeid!!:",commenttypeid)
if commenttypeid is not None and commenttypeid != data["commenttypeid"]:
childresult = FOIRequestComment.updatechildcomments(commentid, data, userid)
if childresult.success == True:
childcomments = childresult.args[2]
#print("childcomments:",childcomments)
if childcomments is not None:
FOIRequestComment.deactivatechildcomments(commentid, userid, childcomments)
if result and deactivateresult:
return result
return DefaultMethodResult(False,'Error in editing comment',commentid)
Expand All @@ -62,6 +71,15 @@ def updaterawrequestcomment(self, commentid, data, userid):
commentsversion = result.args[1]
if commentsversion and commentsversion > 0:
deactivateresult = FOIRawRequestComment.deactivatecomment(commentid, userid, commentsversion)
commenttypeid = result.args[2]
#print("commenttypeid!:",commenttypeid)
if commenttypeid is not None and commenttypeid != data["commenttypeid"]:
childresult = FOIRawRequestComment.updatechildcomments(commentid, data, userid)
if childresult.success == True:
childcomments = childresult.args[2]
#print("childcomments:",childcomments)
if childcomments is not None:
FOIRawRequestComment.deactivatechildcomments(commentid, userid, childcomments)
if result and deactivateresult:
return result
return DefaultMethodResult(False,'Error in editing raw request comment',commentid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,39 @@ def __getassignees(self, foirequest, requesttype, notificationtype, requestjson=


def __isiaointernalcomment(self, notificationtype, requestjson):
if(notificationtype in ["New User Comments", "Reply User Comments", "Tagged User Comments"] and
'commenttypeid' in requestjson and (requestjson['commenttypeid'] == commentservice().getcommenttypeidbyname("IAO Internal") or
requestjson['commenttypeid'] == commentservice().getcommenttypeidbyname("IAO Peer Review"))):
_iaointernaltype= commentservice().getcommenttypeidbyname("IAO Internal")
_iaopeerreviewtype= commentservice().getcommenttypeidbyname("IAO Peer Review")
if(notificationtype in ["New User Comments", "Reply User Comments", "Tagged User Comments", "General"] and
'commenttypeid' in requestjson and (requestjson['commenttypeid'] == _iaointernaltype or
requestjson['commenttypeid'] == _iaopeerreviewtype)):
return True
else:
return False

def __isministryinternalcomment(self, notificationtype, requestjson):
if(notificationtype in ["New User Comments", "Reply User Comments", "Tagged User Comments"] and
'commenttypeid' in requestjson and (requestjson['commenttypeid'] == commentservice().getcommenttypeidbyname("Ministry Internal") or
requestjson['commenttypeid'] == commentservice().getcommenttypeidbyname("Ministry Peer Review"))):
ministryinternaltype= commentservice().getcommenttypeidbyname("Ministry Internal")
ministrypeerreviewtype= commentservice().getcommenttypeidbyname("Ministry Peer Review")
print("ministryinternaltype:",ministryinternaltype)
print("ministrypeerreviewtype:",ministrypeerreviewtype)
print("requestjson:",requestjson)
if(notificationtype in ["New User Comments", "Reply User Comments", "Tagged User Comments", "General"] and
'commenttypeid' in requestjson and (requestjson['commenttypeid'] == ministryinternaltype or
requestjson['commenttypeid'] == ministrypeerreviewtype)):
return True
else:
return False

def __isministryassigneeneeded(self, requesttype, foirequest, notificationtype, requestjson=None):
if(requesttype == "ministryrequest" and foirequest["assignedministryperson"] is not None and (notificationtype == 'Ministry Assignment' or 'Assignment' not in notificationtype)):
if 'Comments' in notificationtype and self.__isiaointernalcomment(notificationtype,requestjson):
if ('Comments' in notificationtype or 'General' in notificationtype) and self.__isiaointernalcomment(notificationtype,requestjson):
return False
return True
else:
return False

def __isfoiassigneeneeded(self, foirequest, notificationtype, requestjson=None):
if self.__isministryonly(notificationtype) == False and foirequest["assignedto"] is not None and foirequest["assignedto"] != '' and (notificationtype == 'IAO Assignment' or 'Assignment' not in notificationtype):
if 'Comments' in notificationtype and self.__isministryinternalcomment(notificationtype,requestjson):
if ('Comments' in notificationtype or 'General' in notificationtype) and self.__isministryinternalcomment(notificationtype,requestjson):
return False
return True
else:
Expand All @@ -125,7 +132,8 @@ def __isministryonly(self, notificationtype):
return True if notificationtype == "Division Due Reminder" else False

def __getcommentusers(self, foirequest, comment, requesttype):
_requestusers = self.getnotificationusers("General", requesttype, "nouser", foirequest)
_requestusers = self.getnotificationusers("General", requesttype, "nouser", foirequest, comment)
print("_requestusers:",_requestusers)
commentusers = []
commentusers.extend(_requestusers)
taggedusers = self.__gettaggedusers(comment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def getministryrequestwatchers(self, ministryrequestid, isministrymember):
return FOIRequestWatcher.getNonMinistrywatchers(ministryrequestid)

def getallministryrequestwatchers(self, ministryrequestid, isministryinternalcomment=False, isiaointernalcomment=False, isministryonly=False):
ministrywatchers = []
if(isiaointernalcomment == False):
ministrywatchers = FOIRequestWatcher.getMinistrywatchers(ministryrequestid)
if isministryonly == False and isministryinternalcomment == False:
Expand Down
Loading