Do I have permission? The Challenge

Given a string indicating the symbolic notation of UNIX permission of a file and its ownership (user ID and group ID), decide whether a given user A has permission to read / write / execute it.

Related.

Permissions in UNIX system

In UNIX, every file has three classes of permissions (user, group and others) and ownership, including which user and which group it belongs to.

The symbolic notation consists of ten characters. The first character is not important in this challenge. The remaining nine characters are in three sets of three characters, representing permissions of user, group and others class. Characters in each set indicates whether reading / writing / executing is permitted. If permitted, it will be r, w or x. Otherwise, it will be -.

Note that setuid, setgid and sticky bit may change the third character of each set to s, S, t or T. Here's a simple rule: if the character is lowercase letter, then the permission is set; otherwise, it is not.

(For the details of symbolic notation of permissions, please refer to here.)

Every user has its user ID, and every group has its group ID. All IDs will be non-negative integers. A user will belong to at least one group. If a user A want to get access to a file, the system will check their permissions as follows:


If the file belongs to user A, check the permissions of user class.
If the file doesn't belong to A, but A belongs to the group which the file belongs to, check the permissions of group class.
Otherwise, check the permissions of others class.


However, there is one exception: if the user ID is 0 (superuser), they have permission to do anything!

Specifications


Your program / function should take these as input in any reasonable format:


Permissions in symbolic notation.
User ID and group ID which the file belongs to.
The user ID of A, and a list of group IDs which A belongs to.
Type of access. You can use any three different one-digit or one-character values for read, write and execute.

Return / output a truthy value if A has permission to access the file, or a falsy value if not.
You can assume that the first character of the notation will always be - (regular file).
This is code-golf, so the shortest in bytes wins!


Test Cases

The format here is [permissions, user ID of file, group ID of file, user ID of A, group IDs of A, type(r/w/x)].

[-rwx------, 13, 15, 13, [15, 24], r]: True   # user
[-rwxr-xr-x, 13, 24, 24, [15, 24], w]: False  # group 
[-rwxr-Sr-T, 13, 15, 24, [15, 35], x]: False  # group
[-rwsr-xr-t, 13, 15, 24, [24, 35], x]: True   # others
[----------, 13, 15, 0, [0, 1, 2], r]: True   # superuser
[----------, 13, 15, 1, [0, 1, 2], r]: False  # others
[----rwxrwx, 13, 15, 13, [15, 24], r]: False  # user
JavaScript (ES6), 61 51 50 bytes

Takes 6 distinct parameters as input, in the order described in the challenge. Expects the last parameter to be 1 for read, 2 for write or 3 for execute. Returns 0 or 1.

(p,u,g,a,G,P)=&gt;!a|p[u-a?6-3*G.includes(g)+P:P]&gt;'Z'


Test cases



let f =

(p,u,g,a,G,P)=&gt;!a|p[u-a?6-3*G.includes(g)+P:P]&gt;'Z'

//            p             u   g   a   G          P
console.log(f('-rwx------', 13, 15, 13, [15, 24],  1)) // True  (user)
console.log(f('-rwxr-xr-x', 13, 24, 24, [15, 24],  2)) // False (group)
console.log(f('-rwxr-Sr-T', 13, 15, 24, [15, 35],  3)) // False (group)
console.log(f('-rwsr-xr-t', 13, 15, 24, [24, 35],  3)) // True  (others)
console.log(f('----------', 13, 15,  0, [0, 1, 2], 1)) // True  (superuser)
console.log(f('----------', 13, 15,  1, [0, 1, 2], 1)) // False (others)
console.log(f('----rwxrwx', 13, 15, 13, [15, 24],  1)) // False (user)