| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- import { Collection, Model } from 'js-abstract-model'
- class User extends Model {
- constructor (data) {
- super(data, [
- // {
- // key: 'baseRoute',
- // default: API_ADDRESS.user.base
- // },
- { key: 'id' },
- { key: 'firstname' },
- { key: 'lastname' },
- { key: 'gender' },
- { key: 'marital_status' },
- { key: 'birthdate' },
- { key: 'national_code' },
- { key: 'picture' },
- { key: 'has_seminary_education' },
- { key: 'has_overdue_instalment' },
- { key: 'last_academic_degree' },
- { key: 'last_academic_degree_field' },
- { key: 'last_academy_name' },
- { key: 'educational_status' },
- { key: 'phone_number' },
- { key: 'phone_number_verified' },
- { key: 'on_social_network_mobile_number' },
- { key: 'on_call_mobile_number' },
- { key: 'email' },
- { key: 'email_verified' },
- { key: 'is_abroad_birth_address' },
- { key: 'birth_country' },
- { key: 'birth_province' },
- { key: 'birth_city' },
- { key: 'is_abroad_living_address' },
- { key: 'living_country' },
- { key: 'living_province' },
- { key: 'living_city' },
- { key: 'living_address' },
- { key: 'living_postal_code' },
- { key: 'living_address_additional_info' },
- { key: 'is_locked_out' },
- { key: 'failed_login_attempts' },
- { key: 'lockout_end_date' },
- { key: 'creation_time' },
- { key: 'last_modification_time' },
- { key: 'is_active' },
- { key: 'is_deleted' },
- { key: 'roles' },
- { key: 'user_id' },
- { key: 'groups' },
- { key: 'is_delete' },
- { key: 'is_superuser' },
- { key: 'last_login' },
- { key: 'mobile_number' },
- { key: 'mobile_number_verified' },
- { key: 'nickname' },
- { key: 'father_name' },
- { key: 'password' },
- { key: 'potential_dates' },
- { key: 'address' },
- { key: 'moballegh_info' },
- { key: 'user_permissions' }
- ], {
- gender: {
- infoKey: 'gender_info',
- enumListKey: 'genderEnums',
- enums: [
- {
- label: 'مذکر',
- value: 1
- },
- {
- label: 'مونث',
- value: 0
- }
- ]
- }
- })
- if (this.user_id !== null) {
- this.id = this.user_id
- }
- }
- fullname () {
- const firstname = this.firstname ? this.firstname : ''
- const lastname = this.lastname ? this.lastname : ''
- return firstname + ' ' + lastname
- }
- hasRole (targetName) {
- if (!this.roles) {
- return false
- }
- return !!this.roles.find(role => role === targetName)
- }
- isSuperUser () {
- return this.hasRole('superuser')
- }
- isAdmin () {
- return this.hasRole('admin')
- }
- isTeamLeader () {
- return this.hasRole('team_leader')
- }
- isEducationalDepartmentHead () {
- return this.hasRole('educational_department_head')
- }
- isResearchDepartmentHead () {
- return this.hasRole('research_department_head')
- }
- isPublicRelationsDepartmentHead () {
- return this.hasRole('public_relations_department_head')
- }
- isDocumentaryDepartmentHead () {
- return this.hasRole('documentary_department_head')
- }
- isHumanResourceDepartmentHead () {
- return this.hasRole('human_resource_department_head')
- }
- isFinancialDepartmentHead () {
- return this.hasRole('financial_department_head')
- }
- isCulturalDepartmentHead () {
- return this.hasRole('cultural_department_head')
- }
- isMediumDepartmentHead () {
- return this.hasRole('medium_department_head')
- }
- isGrader () {
- return this.hasRole('grader')
- }
- isProfessor () {
- return this.hasRole('professor')
- }
- isUser () {
- return this.hasRole('user')
- }
- canSeeUserProfilePanel () {
- return this.isUser()
- }
- canSeeAdminPanel () {
- return (
- this.isSuperUser() ||
- this.isAdmin() ||
- this.isTeamLeader() ||
- this.isEducationalDepartmentHead() ||
- this.isResearchDepartmentHead() ||
- this.isPublicRelationsDepartmentHead() ||
- this.isDocumentaryDepartmentHead() ||
- this.isHumanResourceDepartmentHead() ||
- this.isFinancialDepartmentHead() ||
- this.isCulturalDepartmentHead() ||
- this.isMediumDepartmentHead() ||
- this.isGrader() ||
- this.isProfessor()
- )
- }
- }
- class UserList extends Collection {
- model () {
- return User
- }
- }
- export { User, UserList }
|