Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gnukhata
gkcore
Commits
a93cc7f8
Commit
a93cc7f8
authored
Nov 30, 2017
by
Prajkta Patkar
Committed by
Nitesh Laxman Chaughule
Dec 19, 2017
Browse files
new function added which take userrole and gives all users data having
same userrole
parent
459cef58
Changes
2
Hide whitespace changes
Inline
Side-by-side
gkcore/views/api_account.py
View file @
a93cc7f8
...
@@ -24,7 +24,8 @@ Contributors:
...
@@ -24,7 +24,8 @@ Contributors:
"Krishnakant Mane" <kk@gmail.com>
"Krishnakant Mane" <kk@gmail.com>
"Ishan Masdekar " <imasdekar@dff.org.in>
"Ishan Masdekar " <imasdekar@dff.org.in>
"Navin Karkera" <navin@dff.org.in>
"Navin Karkera" <navin@dff.org.in>
Prajkta Patkar" <prajakta@dff.org.in>
"Prajkta Patkar" <prajakta@dff.org.in>
"Prajkta Patkar" <prajkta.patkar007@gmail.com>
"""
"""
from
gkcore
import
eng
,
enumdict
from
gkcore
import
eng
,
enumdict
...
...
gkcore/views/api_user.py
View file @
a93cc7f8
...
@@ -24,7 +24,7 @@ Contributors:
...
@@ -24,7 +24,7 @@ Contributors:
"Ishan Masdekar " <imasdekar@dff.org.in>
"Ishan Masdekar " <imasdekar@dff.org.in>
"Navin Karkera" <navin@dff.org.in>
"Navin Karkera" <navin@dff.org.in>
"Mohd. Talha Pawaty" <mtalha456@gmail.com>
"Mohd. Talha Pawaty" <mtalha456@gmail.com>
Prajkta Patkar <prajakta@dff.org.in>
"
Prajkta Patkar
"
<prajakta@dff.org.in>
"""
"""
...
@@ -165,6 +165,66 @@ class api_user(object):
...
@@ -165,6 +165,66 @@ class api_user(object):
return
{
"gkstatus"
:
gkcore
.
enumdict
[
"ConnectionFailed"
]
}
return
{
"gkstatus"
:
gkcore
.
enumdict
[
"ConnectionFailed"
]
}
finally
:
finally
:
self
.
con
.
close
()
self
.
con
.
close
()
"""
Following function is to get all users data having same user role .It needs userrole & only admin can view data of other users.
"""
@
view_config
(
route_name
=
'user'
,
request_method
=
'GET'
,
request_param
=
"sameRoleUsers"
,
renderer
=
'json'
)
def
getAllUsersData
(
self
):
try
:
token
=
self
.
request
.
headers
[
"gktoken"
]
except
:
return
{
"gkstatus"
:
enumdict
[
"UnauthorisedAccess"
]}
authDetails
=
authCheck
(
token
)
if
authDetails
[
"auth"
]
==
False
:
return
{
"gkstatus"
:
enumdict
[
"UnauthorisedAccess"
]}
else
:
try
:
self
.
con
=
eng
.
connect
()
# get user role to validate.
# only admin can view all users entire data
user
=
self
.
con
.
execute
(
select
([
gkdb
.
users
.
c
.
userrole
]).
where
(
gkdb
.
users
.
c
.
userid
==
authDetails
[
"userid"
]
))
userRole
=
user
.
fetchone
()
if
userRole
[
0
]
==-
1
:
# get all users having same user role.
result
=
self
.
con
.
execute
(
select
([
gkdb
.
users
.
c
.
username
,
gkdb
.
users
.
c
.
userid
,
gkdb
.
users
.
c
.
userquestion
,
gkdb
.
users
.
c
.
useranswer
]).
where
(
and_
(
gkdb
.
users
.
c
.
userrole
==
self
.
request
.
params
[
"userrole"
]
,
gkdb
.
users
.
c
.
orgcode
==
authDetails
[
"orgcode"
])))
userData
=
result
.
fetchall
()
usersList
=
[]
for
row
in
userData
:
User
=
{
"userid"
:
row
[
"userid"
],
"username"
:
row
[
"username"
],
"userrole"
:
self
.
request
.
params
[
"userrole"
],
"userquestion"
:
row
[
"userquestion"
],
"useranswer"
:
row
[
"useranswer"
]}
# -1 = admin, 0 = Manager ,1 = operator,2 = Internal Auditor , 3 = godown in charge
if
int
(
self
.
request
.
params
[
"userrole"
])
==
-
1
:
User
[
"userroleName"
]
=
"Admin"
elif
int
(
self
.
request
.
params
[
"userrole"
]
==
0
):
User
[
"userroleName"
]
=
"Manager"
elif
int
(
self
.
request
.
params
[
"userrole"
]
==
1
):
User
[
"userroleName"
]
=
"Operator"
elif
int
(
self
.
request
.
params
[
"userrole"
]
==
2
):
User
[
"userroleName"
]
=
"Internal Auditor"
# if user is godown in-charge we need to retrive associated godown/s
elif
int
(
self
.
request
.
params
[
"userrole"
])
==
3
:
User
[
"userroleName"
]
=
"Godown In Charge"
usgo
=
self
.
con
.
execute
(
select
([
gkdb
.
usergodown
.
c
.
goid
]).
where
(
gkdb
.
users
.
c
.
userid
==
row
[
"userid"
]))
goids
=
usgo
.
fetchall
()
userGodowns
=
{}
for
g
in
goids
:
godownid
=
g
[
"goid"
]
# now we have associated godown ids, by which we can get godown name
godownData
=
self
.
con
.
execute
(
select
([
gkdb
.
godown
.
c
.
goname
]).
where
(
gkdb
.
godown
.
c
.
goid
==
godownid
))
gNameRow
=
godownData
.
fetchone
()
userGodowns
[
godownid
]
=
gNameRow
[
"goname"
]
User
[
"godowns"
]
=
userGodowns
usersList
.
append
(
User
)
return
{
"gkstatus"
:
gkcore
.
enumdict
[
"Success"
],
"gkresult"
:
usersList
}
else
:
return
{
"gkstatus"
:
gkcore
.
enumdict
[
"ActionDisallowed"
]}
except
:
return
{
"gkstatus"
:
gkcore
.
enumdict
[
"ConnectionFailed"
]
}
finally
:
self
.
con
.
close
()
@
view_config
(
request_method
=
'PUT'
,
renderer
=
'json'
)
@
view_config
(
request_method
=
'PUT'
,
renderer
=
'json'
)
def
editUser
(
self
):
def
editUser
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment