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

FWF-3972 [bugfix] fixed application authorization fixed for submitter only #2401

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
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
7 changes: 5 additions & 2 deletions forms-flow-web/src/components/Form/EditForm/FormSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ 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 stored in 'resourceDetails'. If the roles array is not empty
we assume that the submitter is true. */
}

});

/* ------------------------- validating form name and path ------------------------ */
Expand Down
Loading