question

Danielle Cox avatar image
Danielle Cox asked Danielle Cox commented

Employee Permissions - See if role has permission to do X

I have a part of my app that is performing something related to refunding an item. However, an action must also be taken in my app. I would like to verify the "role" based permissions for Register - Refund And Exchange Items to make sure I have this. How can I query if a role (or Employee) has a specific Permission? This is Android SDK.

I don't see how to add Permissions or Roles as Topics in this post.
Employees
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Dan avatar image
Dan answered Danielle Cox commented
You can use
public boolean isPermissionAllowed(String permissionSetName, String packageName, String employeeId, AccountRole minimumRole)
in Roles.java in clover-android-sdk

I don't see a list of permission set names and packages, but you should be able to get the names from a sandbox app by querying the on device database using RolesContract.java.

For example:
Uri uri = RolesContract.PermissionSets.contentUriWithAccount(CloverAccount.getAccount(MainActivity.this));
ContentProviderClient client = getContentResolver().acquireUnstableContentProviderClient(uri);
if (client != null) {
  Cursor cursor = null;

  try {
    cursor = client.query(RolesContract.PermissionSets.contentUriWithAccount(CloverAccount.getAccount(MainActivity.this)), null, null, null, null);
    if (cursor != null) {
      for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
        String name = cursor.getString(cursor.getColumnIndex(RolesContract.PermissionSets.NAME));
        String label = cursor.getString(cursor.getColumnIndex(RolesContract.PermissionSets.LABEL));
        Log.i("FetchPermissionSets", String.format("name: %s, label: %s", name, label));
      }
    }
  } catch (Exception e) {
    e.printStackTrace();
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
}

Then you can manually get the package names by looking at the Permissions tab in com.clover.employees. The package name is the package name corresponding to the group that the permission is under.

For example, Perform manual refund for manual transaction falls under:
I/PermissionSets( 5547): name: PERFORM_MANUAL_REFUND, label: Perform manual refund
package:com.clover.manualtransaction

If you want to test isPermissionAllowed(...) before digging up your specific permission set, can try ADD_CUSTOM_DISCOUNT for com.clover.register (corresponds to Apply custom discounts in register)

You can use EmployeeConnector#getEmployee() to get the active employee.
A sample call is:
Roles.isPermissionAllowed("ADD_CUSTOM_DISCOUNT", "com.clover.register", activeEmployee.getId(), null)
3 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Danielle Cox avatar image Danielle Cox commented ·

I saw that, but I don't see the permissionSetName definitions to know which one to ask for ?

0 Likes 0 ·
Dan avatar image Dan ♦ Danielle Cox commented ·

i updated the question since comment character limits are too low to paste code.

0 Likes 0 ·
Danielle Cox avatar image Danielle Cox Dan ♦ commented ·

Thank you!!

0 Likes 0 ·

Welcome to the
Clover Developer Community