Ok, have one table for each object or entity, users and departments. To store permissions you need an table that has references to both of these tables.
userTable
pkColumn
username
other
departmentTable
pkColumn
departmentName
other
permissionsTable
user -- foreign key to userTable
department -- foreign key to departmentTable
permission attributes
When a user gets permission on a department, add a row to the permissionTable and delete it when he loses the permission.
When defining the foreign keys you can use
on cascade delete
which means that if a user/department is deleted the referencing rows in the permissions table are also deleted.
create table users(id int, name varchar(30),primary key(id))
-- possibly other columns
create table departments(id int, name varchar(30),primary key(id))
-- possibly other columns
create table permissions(userid int references users on delete cascade, departmentid references departments on delete cascade)
You may wish to setup the primary key columns as auto_increment or counter. Exactly how this is done depends on which dbms you are using.