V
V
v- death2015-08-17 17:19:56
MySQL
v- death, 2015-08-17 17:19:56

Am I making a table with permissions correctly?

Hello. There is a task.
We need to assign rights. When calling the API method, I drag the field from the table and see if 0 then access is closed. If 1 then everything is ok.
The actual table

type UseApi struct {
  KeyId           int    `sql:"AUTO_INCREMENT"                gorm:"primary_key"`
  ApiKey          string `sql:"type:varchar(13)   ;not null"  gorm:"unique_index"`
  ApiAuthRedirekt string `sql:"type:varchar(100)  ;not null"`

  //0 прав нет 1 права есть
  RightsAuth                         int `sql:"type:varchar(1)    ;not null"`
  RightsRegs                         int `sql:"type:varchar(1)    ;not null"`
  RightsBattlesInvasion              int `sql:"type:varchar(1)    ;not null"` //война
  RightsBattlesSanctions             int `sql:"type:varchar(1)    ;not null"`
  RightsBattlesGround                int `sql:"type:varchar(1)    ;not null"`
  RightsMissionsLocation             int `sql:"type:varchar(1)    ;not null"` //мисии
  RightsMissionsHq                   int `sql:"type:varchar(1)    ;not null"`
  RightsUnitsMarket                  int `sql:"type:varchar(1)    ;not null"` //Магазин техники
  RightsBlackmarketMercenaries       int `sql:"type:varchar(1)    ;not null"` //чёрный рынок
  RightsBlackmarketSaboteurs         int `sql:"type:varchar(1)    ;not null"`
  RightsBlackmarketLaboratory        int `sql:"type:varchar(1)    ;not null"`
  RightsBlackmarketContraband        int `sql:"type:varchar(1)    ;not null"`
  RightsBlackmarketDocuments         int `sql:"type:varchar(1)    ;not null"`
  RightsBlackmarketAuction           int `sql:"type:varchar(1)    ;not null"` //Производство
  RightsManufacturingFactory         int `sql:"type:varchar(1)    ;not null"`
  RightsManufacturingMines           int `sql:"type:varchar(1)    ;not null"`
  RightsManufacturingRockets         int `sql:"type:varchar(1)    ;not null"`
  RightsBuildingsProfitable          int `sql:"type:varchar(1)    ;not null"` //постройки
  RightsBuildingsDefense             int `sql:"type:varchar(1)    ;not null"`
  RightsBuildingsEnergy              int `sql:"type:varchar(1)    ;not null"`
  RightsOfficersclubResling          int `sql:"type:varchar(1)    ;not null"` //клуб офицеров
  RightsOfficersclubRoulette         int `sql:"type:varchar(1)    ;not null"`
  RightsOfficersclubSpyInterrogation int `sql:"type:varchar(1)    ;not null"`
  RightsOfficersclubVeteransRiddle   int `sql:"type:varchar(1)    ;not null"`
  RightsOfficersclubWallNewspaper    int `sql:"type:varchar(1)    ;not null"`
  RightsProfileInfo                  int `sql:"type:varchar(1)    ;not null"` //профиль
  RightsProfileSkills                int `sql:"type:varchar(1)    ;not null"`
  RightsProfileAchievements          int `sql:"type:varchar(1)    ;not null"`
  RightsProfileProperty              int `sql:"type:varchar(1)    ;not null"`
  RightsProfileBooty                 int `sql:"type:varchar(1)    ;not null"`
  RightsProfileGifts                 int `sql:"type:varchar(1)    ;not null"`
  RightsProfileVipMode               int `sql:"type:varchar(1)    ;not null"`
  RightsProfileStatistic             int `sql:"type:varchar(1)    ;not null"`
  RightsHalloffameRating             int `sql:"type:varchar(1)    ;not null"` //зал славы
  RightsHalloffameStatistic          int `sql:"type:varchar(1)    ;not null"`
  RightsHalloffameHeroes             int `sql:"type:varchar(1)    ;not null"`
  RightsHalloffameLegions            int `sql:"type:varchar(1)    ;not null"`
  RightsAllianceIndex                int `sql:"type:varchar(1)    ;not null"` //альянс
  RightsAllianceRequests             int `sql:"type:varchar(1)    ;not null"`
  RightsAllianceReferrals            int `sql:"type:varchar(1)    ;not null"`
  RightsAllianceReinforcement        int `sql:"type:varchar(1)    ;not null"`
  RightsAllianceUnderDefense         int `sql:"type:varchar(1)    ;not null"`
  RightsChatPublic                   int `sql:"type:varchar(1)    ;not null"` //чаты
  RightsChatAlliance                 int `sql:"type:varchar(1)    ;not null"`
  RightsChatLegions                  int `sql:"type:varchar(1)    ;not null"`
  RightsChatBootcamp                 int `sql:"type:varchar(1)    ;not null"`
  RightsBankStorage                  int `sql:"type:varchar(1)    ;not null"` // банк
  RightsBankGold                     int `sql:"type:varchar(1)    ;not null"`
  RightsBankСredit                   int `sql:"type:varchar(1)    ;not null"`
  RightsBankExchanger                int `sql:"type:varchar(1)    ;not null"`
  RightsMailIndex                    int `sql:"type:varchar(1)    ;not null"` //почта
  RightsMailWrite                    int `sql:"type:varchar(1)    ;not null"`
  RightsMailContacts                 int `sql:"type:varchar(1)    ;not null"`
  RightsMailIgnore                   int `sql:"type:varchar(1)    ;not null"`
  RightsHospital                     int `sql:"type:varchar(1)    ;not null"` //госпиталь
  RightsNews                         int `sql:"type:varchar(1)    ;not null"` //Новости
  RightsNewsAddCommen                int `sql:"type:varchar(1)    ;not null"`
  RightsdailyBonus                   int `sql:"type:varchar(1)    ;not null"`
}

She came out very big. Thanks in advance.
Since reading is faster with MyISAM, this type of Pruff table will be used.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Андрей Павленко, 2015-08-17
@vGrabko99

Плохо, лучше бы просто хранить в отдельной таблице все варианты прав и их соотношения (к примеру, есть поле manageNews, который включает в себя deleteNews, updateNews) и отдельную таблицу для соотношений - какой пользователь имеет какие права.
https://github.com/yiisoft/yii2-framework/blob/mas...
Пусть это и php-фреймворк, но можно посмотреть пример работы таблицы; заодно в документации можно найти, как все это работает.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question