Provide ability for admins to manage user organisation membership & admin rights
- Required overwriting a bunch of base code to slot in the handling - Admins are shown with yellow text in their organisation label
This commit is contained in:
@@ -254,4 +254,20 @@ class Organisation extends Model implements OrganisationInterface
|
||||
$join->on('admin_counts.organisation_id', '=', 'organisations.id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Query scope to get all organisations a specific user is a member of.
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param int $userId
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function scopeForUser($query, $userId)
|
||||
{
|
||||
return $query->join('organisation_members', function ($join) use ($userId) {
|
||||
$join->on('organisation_members.organisation_id', 'organisations.id')
|
||||
->where('user_id', $userId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class User extends UFUser
|
||||
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
|
||||
$classMapper = static::$ci->classMapper;
|
||||
|
||||
return $this->belongsToMany($classMapper->getClassMapping('organisation'), 'organisation_members', 'user_id', 'organisation_id');
|
||||
return $this->belongsToMany($classMapper->getClassMapping('organisation'), 'organisation_members', 'user_id', 'organisation_id')->withPivot('flag_admin');;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user