User.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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: 'has_overdue_instalment' },
  19. { key: 'last_academic_degree' },
  20. { key: 'last_academic_degree_field' },
  21. { key: 'last_academy_name' },
  22. { key: 'educational_status' },
  23. { key: 'phone_number' },
  24. { key: 'phone_number_verified' },
  25. { key: 'on_social_network_mobile_number' },
  26. { key: 'on_call_mobile_number' },
  27. { key: 'email' },
  28. { key: 'email_verified' },
  29. { key: 'is_abroad_birth_address' },
  30. { key: 'birth_country' },
  31. { key: 'birth_province' },
  32. { key: 'birth_city' },
  33. { key: 'is_abroad_living_address' },
  34. { key: 'living_country' },
  35. { key: 'living_province' },
  36. { key: 'living_city' },
  37. { key: 'living_address' },
  38. { key: 'living_postal_code' },
  39. { key: 'living_address_additional_info' },
  40. { key: 'is_locked_out' },
  41. { key: 'failed_login_attempts' },
  42. { key: 'lockout_end_date' },
  43. { key: 'creation_time' },
  44. { key: 'last_modification_time' },
  45. { key: 'is_active' },
  46. { key: 'is_deleted' },
  47. { key: 'roles' },
  48. { key: 'user_id' },
  49. { key: 'groups' },
  50. { key: 'is_delete' },
  51. { key: 'is_superuser' },
  52. { key: 'last_login' },
  53. { key: 'mobile_number' },
  54. { key: 'mobile_number_verified' },
  55. { key: 'nickname' },
  56. { key: 'father_name' },
  57. { key: 'password' },
  58. { key: 'potential_dates' },
  59. { key: 'address' },
  60. { key: 'moballegh_info' },
  61. { key: 'user_permissions' }
  62. ], {
  63. gender: {
  64. infoKey: 'gender_info',
  65. enumListKey: 'genderEnums',
  66. enums: [
  67. {
  68. label: 'مذکر',
  69. value: 1
  70. },
  71. {
  72. label: 'مونث',
  73. value: 0
  74. }
  75. ]
  76. }
  77. })
  78. if (this.user_id !== null) {
  79. this.id = this.user_id
  80. }
  81. }
  82. fullname () {
  83. const firstname = this.firstname ? this.firstname : ''
  84. const lastname = this.lastname ? this.lastname : ''
  85. return firstname + ' ' + lastname
  86. }
  87. hasRole (targetName) {
  88. if (!this.roles) {
  89. return false
  90. }
  91. return !!this.roles.find(role => role === targetName)
  92. }
  93. isSuperUser () {
  94. return this.hasRole('superuser')
  95. }
  96. isAdmin () {
  97. return this.hasRole('admin')
  98. }
  99. isTeamLeader () {
  100. return this.hasRole('team_leader')
  101. }
  102. isEducationalDepartmentHead () {
  103. return this.hasRole('educational_department_head')
  104. }
  105. isResearchDepartmentHead () {
  106. return this.hasRole('research_department_head')
  107. }
  108. isPublicRelationsDepartmentHead () {
  109. return this.hasRole('public_relations_department_head')
  110. }
  111. isDocumentaryDepartmentHead () {
  112. return this.hasRole('documentary_department_head')
  113. }
  114. isHumanResourceDepartmentHead () {
  115. return this.hasRole('human_resource_department_head')
  116. }
  117. isFinancialDepartmentHead () {
  118. return this.hasRole('financial_department_head')
  119. }
  120. isCulturalDepartmentHead () {
  121. return this.hasRole('cultural_department_head')
  122. }
  123. isMediumDepartmentHead () {
  124. return this.hasRole('medium_department_head')
  125. }
  126. isGrader () {
  127. return this.hasRole('grader')
  128. }
  129. isProfessor () {
  130. return this.hasRole('professor')
  131. }
  132. isUser () {
  133. return this.hasRole('user')
  134. }
  135. canSeeUserProfilePanel () {
  136. return this.isUser()
  137. }
  138. canSeeAdminPanel () {
  139. return (
  140. this.isSuperUser() ||
  141. this.isAdmin() ||
  142. this.isTeamLeader() ||
  143. this.isEducationalDepartmentHead() ||
  144. this.isResearchDepartmentHead() ||
  145. this.isPublicRelationsDepartmentHead() ||
  146. this.isDocumentaryDepartmentHead() ||
  147. this.isHumanResourceDepartmentHead() ||
  148. this.isFinancialDepartmentHead() ||
  149. this.isCulturalDepartmentHead() ||
  150. this.isMediumDepartmentHead() ||
  151. this.isGrader() ||
  152. this.isProfessor()
  153. )
  154. }
  155. }
  156. class UserList extends Collection {
  157. model () {
  158. return User
  159. }
  160. }
  161. export { User, UserList }