Ignore:
Timestamp:
08/23/24 15:40:14 (5 weeks ago)
Author:
ElenaMoskova <elena.moskova99@…>
Branches:
main
Children:
e9bb9d1
Parents:
72b1da2
Message:

fix access

implement multiple access pages with different roles
optimize present three structure of BlogPost and Answer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • PostgreSqlDotnetCore/Controllers/CustomerController.cs

    r72b1da2 r118e414  
    1919        public async Task<ActionResult> IndexAsync()
    2020        {
    21             UsersClass customerClass = await getCrrentUser();
     21           UsersClass customerClass = await getCrrentUser();
     22           
     23            ViewBag.isAuthenticated = User.Identity.IsAuthenticated;
     24            ViewBag.CanCreate = customerClass.role_id == RoleConstants.Admin || customerClass.role_id == RoleConstants.Manager;
     25            // no access for standard user
     26            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     27
    2228            if (customerClass == null)
    2329            {
     
    4147                return View(db.CustomerObj.ToList());
    4248            }
    43          
     49
     50
    4451        }
    4552
     
    5764            // check for permission
    5865            UsersClass customerClass = await getCrrentUser();
     66            ViewBag.isAuthenticated = customerClass;
    5967            if (customerClass == null)
    6068            {
     
    6775                return RedirectToAction("NotExist", "Error");
    6876            }
     77            // no access for standard user
     78            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     79
    6980            return View(customerClass);
    7081        }
     
    7384        public async Task<ActionResult> CreateAsync()
    7485        {
     86            //ViewBag.CanCreate = customerClass.role_id == RoleConstants.Admin || customerClass.role_id == RoleConstants.Manager;
     87
    7588            // check for permission
    76             UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin);
    77             if (customerClass == null)
    78             {
    79                 return RedirectToAction("AccessDenied", "Error");
    80             }
     89            UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     90            //dodano na 23.08
     91            ViewBag.isAuthenticated = await getCrrentUser();
     92            if (customerClass == null)
     93            {
     94                return RedirectToAction("AccessDenied", "Error");
     95            }
     96            // no access for standard user
     97            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     98
    8199
    82100            return View();
     
    125143
    126144            customerClass = db.CustomerObj.Find(id);
     145            ViewBag.isAuthenticated = await getCrrentUser();
    127146            if (customerClass == null)
    128147            {
     
    130149                //return HttpNotFound();
    131150            }
     151            // no access for standard user
     152            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     153
    132154            return View(customerClass);
    133155        }
     
    159181            }
    160182            UsersClass customerClass = await getCrrentUser();
    161             if (customerClass == null)
    162             {
    163                 return RedirectToAction("AccessDenied", "Error");
    164             }
     183            ViewBag.isAuthenticated = await getCrrentUser();
     184            if (customerClass == null)
     185            {
     186                return RedirectToAction("AccessDenied", "Error");
     187            }
     188           
     189            // no access for standard user
     190            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
    165191            return View(customerClass);
    166192        }
Note: See TracChangeset for help on using the changeset viewer.