Skip to content

Commit

Permalink
Merge pull request #964 from Rajandeep98/Bug-SBCQ160_GA_Role_Restriction
Browse files Browse the repository at this point in the history
SBCQ160 GA role restricted to csr/ga
  • Loading branch information
josekudiyirippil authored Jul 29, 2024
2 parents 21c0f27 + c5229b5 commit 44fc4bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion api/app/admin/csr.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
See the License for the specific language governing permissions and
limitations under the License.'''

from app.models.theq import Citizen, CSR, CitizenState, Period, PeriodState, ServiceReq, SRState, Counter
from app.models.theq import Citizen, CSR, CitizenState, Period, PeriodState, ServiceReq, SRState, Counter, Role
from flask import flash, redirect, request
from .base import Base
from flask_admin.babel import gettext
Expand Down Expand Up @@ -124,6 +124,11 @@ def validate_model(self):

model = self.get_one(identifier)

allowed_ga_edit_roles = ['GA', 'CSR']
if model and current_user.role.role_code == 'GA' and model.role.role_code not in allowed_ga_edit_roles:
flash(gettext('You are not allowed to edit a '+ model.role.role_code +' role.'), 'error')
return False

if model is None:
flash(gettext('Record does not exist.'), 'error')
return False
Expand Down Expand Up @@ -208,6 +213,11 @@ class CSRConfigGA(CSRConfig):
'finance_designate', 'ita2_designate', 'csr_state', 'role', 'office', 'counter')
form_edit_rules = ('username', 'office_manager', 'pesticide_designate', 'ita2_designate', 'role', 'office')

form_args = {
'role': {
'query_factory': lambda: db.session.query(Role).filter(Role.role_code.in_(['CSR', 'GA']))
}
}

CSRModelView = CSRConfig(CSR, db.session)
CSRGAModelView = CSRConfigGA(CSR, db.session, endpoint='csrga')
Expand Down
2 changes: 1 addition & 1 deletion api/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.1.2'
__version__ = '1.1.3'

0 comments on commit 44fc4bc

Please sign in to comment.