Skip to content

Commit

Permalink
FWF-3972 [bugfix] fixed application authorization fixed for submitter…
Browse files Browse the repository at this point in the history
… only
  • Loading branch information
shuhaib-aot committed Dec 4, 2024
1 parent 3961391 commit d673d96
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
32 changes: 21 additions & 11 deletions forms-flow-api/src/formsflow_api/models/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from enum import Enum, unique
from typing import List, Optional

from sqlalchemy import JSON, and_, or_
from sqlalchemy import JSON, and_, or_, text
from sqlalchemy.dialects.postgresql import ARRAY, ENUM

from .audit_mixin import AuditDateTimeMixin, AuditUserMixin
Expand Down Expand Up @@ -71,17 +71,27 @@ def _auth_query(
cls, auth_type, roles, tenant, user_name, include_created_by=False
): # pylint: disable=too-many-arguments,too-many-positional-arguments
role_condition = [Authorization.roles.contains([role]) for role in roles]
query = cls.query.filter(Authorization.auth_type == auth_type).filter(
or_(
*role_condition,
include_created_by and Authorization.created_by == user_name,
Authorization.user_name == user_name,
and_(
Authorization.user_name.is_(None),
or_(Authorization.roles == {}, Authorization.roles.is_(None)),
),
query = cls.query.filter(Authorization.auth_type == auth_type)
if auth_type == AuthType.APPLICATION:
# if the authtype is application then need to check role id exist or if submitter true
query = query.filter(
or_(
*role_condition,
text("resource_details ->>'submitter' = 'True'"),
)
)
else:
query = query.filter(
or_(
*role_condition,
include_created_by and Authorization.created_by == user_name,
Authorization.user_name == user_name,
and_(
Authorization.user_name.is_(None),
or_(Authorization.roles == {}, Authorization.roles.is_(None)),
),
)
)
)

if tenant:
query = query.filter(Authorization.tenant == tenant)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,9 @@ def create_form(data, is_designer, **kwargs): # pylint:disable=too-many-locals
authorization_data = {
"application": {
"resourceId": parent_form_id,
"resourceDetails": {},
"resourceDetails": {"submitter": True},
"roles": [],
"userName": user.user_name,
"userName": None,
},
"designer": {
"resourceId": parent_form_id,
Expand Down
5 changes: 4 additions & 1 deletion forms-flow-web/src/components/Form/EditForm/FormEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ const EditComponent = () => {

/* ----------- save settings function to be used in settings modal ---------- */
const filterAuthorizationData = (authorizationData) => {
if(authorizationData.selectedOption === "submitter"){
return {roles: [], userName:null, resourceDetails:{submitter:true}};
}
if (authorizationData.selectedOption === "specifiedRoles") {
return { roles: authorizationData.selectedRoles, userName: "" };
}
Expand Down Expand Up @@ -475,7 +478,7 @@ const EditComponent = () => {
const authorizations = {
application: {
resourceId: parentFormId,
resourceDetails: {},
resourceDetails:{submitter:false},
...filterAuthorizationData(rolesState.APPLICATION),
},
designer: {
Expand Down
3 changes: 2 additions & 1 deletion forms-flow-web/src/components/Form/EditForm/FormSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ const FormSettings = forwardRef((props, ref) => {
APPLICATION: {
roleInput: "",
selectedRoles: formAuthorization.APPLICATION?.roles,
selectedOption: setSelectedOption(formAuthorization.APPLICATION?.roles, "submitter"),
selectedOption: setSelectedOption(formAuthorization.APPLICATION?.roles, "submitter"),
//the submitter key is keep in resourceDetails but if the rols array is not empty then we can assume this is submitter true
},
});

Expand Down

0 comments on commit d673d96

Please sign in to comment.