User.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import { Collection, Model } from 'js-abstract-model'
  2. class User extends Model {
  3. constructor (data) {
  4. super(data, [
  5. // {
  6. // key: 'baseRoute',
  7. // default: API_ADDRESS.user.base
  8. // },
  9. { key: 'id' },
  10. { key: 'firstname' },
  11. { key: 'lastname' },
  12. { key: 'gender' },
  13. { key: 'marital_status' },
  14. { key: 'birthdate' },
  15. { key: 'national_code' },
  16. { key: 'picture' },
  17. { key: 'has_seminary_education' },
  18. { key: 'last_academic_degree' },
  19. { key: 'last_academic_degree_field' },
  20. { key: 'last_academy_name' },
  21. { key: 'educational_status' },
  22. { key: 'phone_number' },
  23. { key: 'phone_number_verified' },
  24. { key: 'on_social_network_mobile_number' },
  25. { key: 'on_call_mobile_number' },
  26. { key: 'email' },
  27. { key: 'email_verified' },
  28. { key: 'is_abroad_birth_address' },
  29. { key: 'birth_country' },
  30. { key: 'birth_province' },
  31. { key: 'birth_city' },
  32. { key: 'is_abroad_living_address' },
  33. { key: 'living_country' },
  34. { key: 'living_province' },
  35. { key: 'living_city' },
  36. { key: 'living_address' },
  37. { key: 'living_postal_code' },
  38. { key: 'living_address_additional_info' },
  39. { key: 'is_locked_out' },
  40. { key: 'failed_login_attempts' },
  41. { key: 'lockout_end_date' },
  42. { key: 'creation_time' },
  43. { key: 'last_modification_time' },
  44. { key: 'is_active' },
  45. { key: 'is_deleted' },
  46. { key: 'roles' },
  47. { key: 'user_id' },
  48. { key: 'groups' },
  49. { key: 'is_delete' },
  50. { key: 'is_superuser' },
  51. { key: 'last_login' },
  52. { key: 'mobile_number' },
  53. { key: 'mobile_number_verified' },
  54. { key: 'nickname' },
  55. { key: 'father_name' },
  56. { key: 'password' },
  57. { key: 'potential_dates' },
  58. { key: 'address' },
  59. { key: 'moballegh_info' },
  60. { key: 'user_permissions' }
  61. ])
  62. if (this.user_id !== null) {
  63. this.id = this.user_id
  64. }
  65. }
  66. fullname () {
  67. const firstname = this.firstname ? this.firstname : ''
  68. const lastname = this.lastname ? this.lastname : ''
  69. return firstname + ' ' + lastname
  70. }
  71. hasRole (targetName) {
  72. if (!this.roles) {
  73. return false
  74. }
  75. return !!this.roles.find(role => role === targetName)
  76. }
  77. isSuperUser () {
  78. return this.hasRole('superuser')
  79. }
  80. isAdmin () {
  81. return this.hasRole('admin')
  82. }
  83. isTeamLeader () {
  84. return this.hasRole('team_leader')
  85. }
  86. isEducationalDepartmentHead () {
  87. return this.hasRole('educational_department_head')
  88. }
  89. isResearchDepartmentHead () {
  90. return this.hasRole('research_department_head')
  91. }
  92. isPublicRelationsDepartmentHead () {
  93. return this.hasRole('public_relations_department_head')
  94. }
  95. isDocumentaryDepartmentHead () {
  96. return this.hasRole('documentary_department_head')
  97. }
  98. isHumanResourceDepartmentHead () {
  99. return this.hasRole('human_resource_department_head')
  100. }
  101. isFinancialDepartmentHead () {
  102. return this.hasRole('financial_department_head')
  103. }
  104. isCulturalDepartmentHead () {
  105. return this.hasRole('cultural_department_head')
  106. }
  107. isMediumDepartmentHead () {
  108. return this.hasRole('medium_department_head')
  109. }
  110. isGrader () {
  111. return this.hasRole('grader')
  112. }
  113. isProfessor () {
  114. return this.hasRole('professor')
  115. }
  116. isUser () {
  117. return this.hasRole('user')
  118. }
  119. canSeeUserProfilePanel () {
  120. return this.isUser()
  121. }
  122. canSeeAdminPanel () {
  123. return (
  124. this.isSuperUser() ||
  125. this.isAdmin() ||
  126. this.isTeamLeader() ||
  127. this.isEducationalDepartmentHead() ||
  128. this.isResearchDepartmentHead() ||
  129. this.isPublicRelationsDepartmentHead() ||
  130. this.isDocumentaryDepartmentHead() ||
  131. this.isHumanResourceDepartmentHead() ||
  132. this.isFinancialDepartmentHead() ||
  133. this.isCulturalDepartmentHead() ||
  134. this.isMediumDepartmentHead() ||
  135. this.isGrader() ||
  136. this.isProfessor()
  137. )
  138. }
  139. }
  140. class UserList extends Collection {
  141. model () {
  142. return User
  143. }
  144. }
  145. export { User, UserList }